Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2014 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  from numpy import array, asarray, exp, median, inf, log, save, std, sum, zeros 
  27  from minfx.generic import generic_minimise 
  28  from random import gauss 
  29  import re, math 
  30  from sys import version_info 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path, open_read_file 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from pipe_control.pipes import display 
  46  from specific_analyses.relax_disp.checks import check_missing_r1 
  47  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  48  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  49  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  50  from specific_analyses.relax_disp.model import models_info, nesting_param 
  51  from specific_analyses.relax_disp.parameters import linear_constraints 
  52  from status import Status; status = Status() 
  53  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  54  from test_suite.system_tests.base_classes import SystemTestCase 
  55   
  56   
57 -class Relax_disp(SystemTestCase):
58 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 59
60 - def __init__(self, methodName='runTest'):
61 """Skip certain tests if the C modules are non-functional. 62 63 @keyword methodName: The name of the test. 64 @type methodName: str 65 """ 66 67 # Execute the base class method. 68 super(Relax_disp, self).__init__(methodName) 69 70 # Tests to skip. 71 blacklist = [ 72 'test_m61b_data_to_m61b' 73 ] 74 if methodName in blacklist: 75 status.skipped_tests.append([methodName, None, self._skip_type]) 76 77 # Missing module. 78 if not dep_check.C_module_exp_fn: 79 # The list of tests to skip. 80 to_skip = [ 81 "test_bug_atul_srivastava", 82 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 83 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 84 "test_estimate_r2eff_err", 85 "test_estimate_r2eff_err_auto", 86 "test_estimate_r2eff_err_methods", 87 "test_finite_value", 88 "test_exp_fit", 89 "test_m61_exp_data_to_m61", 90 "test_r1rho_kjaergaard_auto", 91 "test_r1rho_kjaergaard_auto_check_graphs", 92 "test_r1rho_kjaergaard_man", 93 "test_r1rho_kjaergaard_missing_r1", 94 "test_value_write_calc_rotating_frame_params_auto_analysis" 95 ] 96 97 # Store in the status object. 98 if methodName in to_skip: 99 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 100 101 # If not scipy.optimize.leastsq. 102 if not dep_check.scipy_module: 103 # The list of tests to skip. 104 to_skip = [ 105 "test_estimate_r2eff_err_methods" 106 ] 107 108 # Store in the status object. 109 if methodName in to_skip: 110 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 111 112 # If not NMRPipe showApod program in PATH. 113 if not dep_check.showApod_software: 114 # The list of tests to skip. 115 to_skip = [ 116 "test_show_apod_extract", 117 "test_show_apod_rmsd", 118 "test_show_apod_rmsd_to_file", 119 "test_show_apod_rmsd_dir_to_files" 120 ] 121 122 # Store in the status object. 123 if methodName in to_skip: 124 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 125 126 # If not matplotlib module 127 if not dep_check.matplotlib_module: 128 # The list of tests to skip. 129 to_skip = [ 130 "test_repeat_cpmg" 131 ] 132 133 # Store in the status object. 134 if methodName in to_skip: 135 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
136 137
138 - def setUp(self):
139 """Set up for all the functional tests.""" 140 141 # Create the data pipe. 142 self.interpreter.pipe.create('relax_disp', 'relax_disp') 143 144 # Create a temporary directory for dumping files. 145 ds.tmpdir = mkdtemp() 146 self.tmpdir = ds.tmpdir
147 148
149 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
150 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 151 152 @keyword folder: The name of the folder for the test data. 153 @type folder: str 154 @keyword model_analyse: The name of the model which will be tested. 155 @type model_analyse: str 156 """ 157 158 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 159 160 # Data. 161 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 162 163 ## Experiments 164 # Exp 1 165 sfrq_1 = 500.0*1E6 166 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 167 time_T2_1 = 0.05 168 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 169 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 170 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 171 r2eff_errs_1 = [0.0] * len(ncycs_1) 172 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 173 174 sfrq_2 = 600.0*1E6 175 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 176 time_T2_2 = 0.06 177 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 178 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 179 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 180 r2eff_errs_2 = [0.0] * len(ncycs_2) 181 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 182 183 sfrq_3 = 700.0*1E6 184 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 185 time_T2_3 = 0.07 186 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 187 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 188 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 189 r2eff_errs_3 = [0.0] * len(ncycs_3) 190 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 191 192 # Collect all exps 193 exps = [exp_1, exp_2, exp_3] 194 195 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 196 dw_arr = [1.0, 2.0, 3.0, 4.0] 197 pA_arr = [0.9] 198 kex_arr = [1000.] 199 200 spins = [ 201 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 202 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 203 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 204 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 205 ] 206 207 # Create the data pipe. 208 pipe_name = 'base pipe' 209 pipe_type = 'relax_disp' 210 pipe_bundle = 'relax_disp' 211 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 212 213 # Generate the sequence. 214 for res_name, res_num, spin_name, params in spins: 215 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 216 217 # Set isotope 218 self.interpreter.spin.isotope('15N', spin_id='@N') 219 220 # Now loop over the experiments, to set the variables in relax. 221 exp_ids = [] 222 for exp_i in exps: 223 sfrq, time_T2, ncycs, r2eff_errs = exp_i 224 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 225 exp_ids.append(exp_id) 226 227 ids = [] 228 for ncyc in ncycs: 229 nu_cpmg = ncyc / time_T2 230 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 231 ids.append(cur_id) 232 233 # Set the spectrometer frequency. 234 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 235 236 # Set the experiment type. 237 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 238 239 # Set the relaxation dispersion CPMG constant time delay T (in s). 240 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 241 242 # Set the relaxation dispersion CPMG frequencies. 243 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 244 245 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 246 247 ### Now do fitting. 248 # Change pipe. 249 250 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 251 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 252 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 253 254 # Now read data in. 255 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 256 exp_id = exp_ids[mi] 257 exp_i = exps[mi] 258 sfrq, time_T2, ncycs, r2eff_errs = exp_i 259 260 # Then loop over the spins. 261 for res_name, res_num, spin_name, params in spins: 262 cur_spin_id = ":%i@%s"%(res_num, spin_name) 263 264 # Define file name 265 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 266 267 # Read in the R2eff file to put into spin structure. 268 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 269 270 # Then select model. 271 self.interpreter.relax_disp.select_model(model=model_analyse) 272 273 # Then cluster 274 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 275 276 # Grid search 277 low_arr = R20 + dw_arr + pA_arr + kex_arr 278 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 279 280 # Then loop over the defined spins and read the parameters. 281 for i in range(len(spins)): 282 res_name, res_num, spin_name, params = spins[i] 283 cur_spin_id = ":%i@%s"%(res_num, spin_name) 284 cur_spin = return_spin(cur_spin_id) 285 286 for mo_param in cur_spin.params: 287 print(mo_param) 288 # The R2 is a dictionary, depending on spectrometer frequency. 289 if isinstance(getattr(cur_spin, mo_param), dict): 290 for key, val in list(getattr(cur_spin, mo_param).items()): 291 should_be = params[mo_param][key] 292 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 293 self.assertAlmostEqual(val, should_be) 294 else: 295 should_be = float(params[mo_param]) 296 val = getattr(cur_spin, mo_param) 297 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 298 self.assertAlmostEqual(val, should_be) 299 300 # Test chi2. 301 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 302 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
303 304
305 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
306 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 307 308 # The path to the data files. 309 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 310 311 # Set pipe name, bundle and type. 312 ds.pipe_name = 'base pipe' 313 ds.pipe_bundle = 'relax_disp' 314 ds.pipe_type = 'relax_disp' 315 316 # Create the data pipe. 317 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 318 319 # Read the spins. 320 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 321 322 # Name the isotope for field strength scaling. 323 self.interpreter.spin.isotope(isotope='15N') 324 325 # Set number of experiments to be used. 326 NR_exp = 70 327 328 # Load the experiments settings file. 329 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 330 expfileslines = expfile.readlines()[:NR_exp] 331 expfile.close() 332 333 # In MHz 334 yOBS = 81.050 335 # In ppm 336 yCAR = 118.078 337 centerPPM_N15 = yCAR 338 339 ## Read the chemical shift data. 340 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 341 342 # The lock power to field, has been found in an calibration experiment. 343 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 344 345 # Apply spectra settings. 346 # Count settings 347 j = 0 348 for i in range(len(expfileslines)): 349 line = expfileslines[i] 350 if line[0] == "#": 351 continue 352 else: 353 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 354 DIRN = line.split()[0] 355 I = int(line.split()[1]) 356 deltadof2 = line.split()[2] 357 dpwr2slock = line.split()[3] 358 ncyc = int(line.split()[4]) 359 trim = float(line.split()[5]) 360 ss = int(line.split()[6]) 361 set_sfrq = float(line.split()[7]) 362 apod_rmsd = float(line.split()[8]) 363 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 364 365 # Calculate spin_lock time 366 time_sl = 2*ncyc*trim 367 368 # Define file name for peak list. 369 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 370 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 371 372 # Load the peak intensities. 373 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 374 375 # Set the peak intensity errors, as defined as the baseplane RMSD. 376 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 377 378 # Set the relaxation dispersion experiment type. 379 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 380 381 # Set The spin-lock field strength, nu1, in Hz 382 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 383 384 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 385 frq_N15_Hz = yOBS * 1E6 386 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 387 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 388 389 # Set The spin-lock offset, omega_rf, in ppm. 390 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 391 392 # Set the relaxation times (in s). 393 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 394 395 # Set the spectrometer frequency. 396 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 397 398 # Add to counter 399 j += 1 400 401 402 print("Testing the number of settings") 403 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 404 self.assertEqual(70, len(expfileslines)) 405 self.assertEqual(69, j) 406 self.assertEqual(69, len(cdp.exp_type)) 407 408 # Cluster spins 409 for curspin in cluster_ids: 410 print("Adding spin %s to cluster"%curspin) 411 self.interpreter.relax_disp.cluster('model_cluster', curspin) 412 413 # De-select for analysis those spins who have not been clustered 414 for free_spin in cdp.clustering['free spins']: 415 print("Deselecting free spin %s"%free_spin) 416 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 417 418 419 #Paper reference values 420 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 421 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 422 ds.ref = dict() 423 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 424 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 425 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 426 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 427 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 428 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 429 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 430 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 431 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 432 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 433 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 434 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 435 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 436 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 437 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 438 439 ds.guess = dict() 440 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 441 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 442 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 443 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 444 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 445 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 446 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 447 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 448 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 449 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 450 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 451 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 452 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 453 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 454 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 455 456 # Assign guess values. 457 for spin, spin_id in spin_loop(return_id=True): 458 if spin_id in cluster_ids: 459 print("spin_id %s in cluster ids"%(spin_id)) 460 spin.kex = ds.guess[spin_id][6] 461 spin.phi_ex = ds.guess[spin_id][10] 462 else: 463 print("spin_id %s NOT in cluster ids"%(spin_id)) 464 465 if read_R1: 466 # Read the R1 data 467 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
468 469
470 - def setup_hansen_cpmg_data(self, model=None):
471 """Set up the data for the test_hansen_cpmg_data_*() system tests. 472 473 @keyword model: The name of the model which will be tested. 474 @type model: str 475 """ 476 477 # Create the data pipe and load the base data. 478 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 479 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 480 self.interpreter.results.read(data_path+sep+'base_pipe') 481 self.interpreter.deselect.spin(':4') 482 483 # Set the nuclear isotope data. 484 self.interpreter.spin.isotope('15N') 485 486 # Create the R2eff data pipe and load the results. 487 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 488 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 489 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 490 self.interpreter.deselect.spin(':4') 491 492 # The model data pipe. 493 pipe_name = "%s - relax_disp" % model 494 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 495 self.interpreter.pipe.switch(pipe_name=pipe_name) 496 497 # Set the model. 498 self.interpreter.relax_disp.select_model(model=model) 499 500 # Copy the data. 501 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
502 503
504 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
505 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 506 507 @keyword model: The name of the model which will be tested. 508 @type model: str 509 """ 510 511 # Create the data pipe and load the base data. 512 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 513 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 514 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 515 516 # Create the R2eff data pipe and load the results. 517 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 518 self.interpreter.pipe.switch(pipe_name='R2eff') 519 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 520 521 # The model data pipe. 522 pipe_name = "%s - relax_disp" % model 523 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 524 self.interpreter.pipe.switch(pipe_name=pipe_name) 525 526 # Set the model. 527 self.interpreter.relax_disp.select_model(model=model) 528 529 # Copy the data. 530 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
531 532
533 - def setup_korzhnev_2005_data(self, data_list=[]):
534 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 535 536 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 537 538 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 539 540 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 541 542 543 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 544 @type data_list: list of str 545 """ 546 547 # Create the data pipe and load the base data. 548 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 549 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 550 551 # Create the spin system. 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 553 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 554 self.interpreter.spin.element('H', spin_id='@H') 555 self.interpreter.spin.element('N', spin_id='@N') 556 self.interpreter.spin.isotope('1H', spin_id='@H') 557 self.interpreter.spin.isotope('15N', spin_id='@N') 558 559 # Define the magnetic dipole-dipole relaxation interaction. 560 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 561 562 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 563 data = [ 564 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 566 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 567 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 569 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 570 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 572 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 575 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 576 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 578 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 581 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 582 ] 583 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 584 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 585 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 587 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 588 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 589 590 # Loop over the files, reading in the data. 591 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 592 # Skip undesired data. 593 if data_type not in data_list: 594 continue 595 596 # Alias the CPMG frequencies. 597 if data_type == 'SQ': 598 cpmg_frqs = cpmg_frqs_sq 599 elif data_type == '1H SQ': 600 cpmg_frqs = cpmg_frqs_1h_sq 601 elif data_type == 'DQ': 602 cpmg_frqs = cpmg_frqs_dq 603 elif data_type == 'ZQ': 604 cpmg_frqs = cpmg_frqs_zq 605 elif data_type == '1H MQ': 606 cpmg_frqs = cpmg_frqs_1h_mq 607 elif data_type == 'MQ': 608 cpmg_frqs = cpmg_frqs_mq 609 610 # Loop over each CPMG frequency. 611 for cpmg_frq in cpmg_frqs: 612 # The id. 613 new_id = "%s_%s" % (id, cpmg_frq) 614 615 # Set the NMR field strength. 616 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 617 618 # Set the relaxation dispersion experiment type. 619 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 620 621 # Relaxation dispersion CPMG constant time delay T (in s). 622 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 623 624 # Set the CPMG frequency. 625 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 626 627 # Read the R2eff data. 628 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 629 630 # Change the model. 631 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
632 633
634 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
635 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 636 637 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 638 'SOD1-WT' CPMG data to the CR72 dispersion model. 639 640 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 641 Data is for experiment at 25 degree Celcius. 642 """ 643 644 # Create the data pipe and load the base data. 645 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 646 647 # Set experiment settings. sfrq, time_T2, ncyc 648 Exps = [ 649 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 650 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 651 652 # Create base pipe 653 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 654 655 # Loop throug experiments 656 id_lists = [] 657 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 658 # Read spins 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 661 662 # Make spectrum id list 663 id_list = list(key+str(i) for i in range(len(ncycs))) 664 id_lists.append(id_list) 665 666 # Read intensities 667 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 668 669 # Loop over experiments 670 for i in range(len(ncycs)): 671 ncyc = ncycs[i] 672 vcpmg = ncyc/time_T2 673 674 # Test if spectrum is a reference 675 if float(vcpmg) == 0.0: 676 vcpmg = None 677 else: 678 vcpmg = round(float(vcpmg), 3) 679 680 # Set current id 681 current_id = id_list[i] 682 683 # Set the current experiment type. 684 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 685 686 # Set the NMR field strength of the spectrum. 687 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 688 689 # Relaxation dispersion CPMG constant time delay T (in s). 690 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 691 692 # Set the relaxation dispersion CPMG frequencies. 693 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 694 695 # Define replicated 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 697 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 698 699 # Perform error analysis 700 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 701 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 702 703 # Define isotope 704 self.interpreter.spin.isotope(isotope='15N') 705 706 ############# 707 708 # Define the 64 residues which was used for Global fitting 709 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 710 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 711 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 712 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 713 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 714 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 715 716 # Test number of global 717 self.assertEqual(64, len(glob_assn )) 718 719 ## Turn assignments into relax spin ids. 720 # Define regular expression search 721 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 722 723 # Create list to hold regular expression search 724 relax_glob_ids = [] 725 726 # Loop over assignments 727 for assn in glob_assn: 728 # Make match for the regular search 729 m = r.match(assn) 730 # Convert to relax spin string 731 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 732 733 # Save the relax spin string and the regular search 734 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 735 736 ############# Deselect all spins, and select few spins 737 738 ## Deselect all spins, and select a few for analysis 739 self.interpreter.deselect.all() 740 741 # Select few spins 742 for i in select_spin_index: 743 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 744 745 ############## 746 747 # Prepare for R2eff calculation 748 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 749 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 750 751 # Select model for points calculation 752 MODEL = "R2eff" 753 self.interpreter.relax_disp.select_model(model=MODEL) 754 # Calculate R2eff values 755 self.interpreter.minimise.calculate(verbosity=1)
756 757
758 - def setup_missing_r1_spins(self):
759 """Function for setting up a few spins for the given pipe.""" 760 761 # Path to file. 762 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 763 764 # File with spins. 765 file = open(data_path+sep+'R1_fitted_values.txt') 766 lines = file.readlines() 767 file.close() 768 769 for i, line in enumerate(lines): 770 # Make the string test 771 line_split = line.split() 772 773 if line_split[0] == "#": 774 continue 775 776 mol_name = line_split[0] 777 mol_name = None 778 res_num = int(line_split[1]) 779 res_name = line_split[2] 780 spin_num = line_split[3] 781 spin_num = None 782 spin_name = line_split[4] 783 784 # Create the spin. 785 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
786 787
788 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
789 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 790 791 # Reset. 792 self.interpreter.reset() 793 794 # Create the data pipe and load the base data. 795 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 796 self.interpreter.state.load(data_path+sep+'r2eff_values') 797 798 # The model data pipe. 799 model = 'NS R1rho 2-site' 800 pipe_name = "%s - relax_disp" % model 801 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 802 self.interpreter.pipe.switch(pipe_name=pipe_name) 803 804 # Set the model. 805 self.interpreter.relax_disp.select_model(model=model) 806 807 # Copy the data. 808 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 809 810 # Alias the spins. 811 spin1 = cdp.mol[0].res[0].spin[0] 812 spin2 = cdp.mol[0].res[1].spin[0] 813 814 # The R20 keys. 815 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 816 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 817 818 # Set the initial parameter values. 819 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 820 spin1.pA = 0.779782428085762 821 spin1.dw = 7.57855284496424 822 spin1.kex = 1116.7911285203 823 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 824 spin2.pA = 0.826666229688602 825 spin2.dw = 9.5732624231366 826 spin2.kex = 1380.46162655657 827 828 # Test the values when clustering. 829 if clustering: 830 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 831 832 # Low precision optimisation. 833 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 834 835 # Printout. 836 print("\n\nOptimised parameters:\n") 837 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 838 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 839 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 840 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 841 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 842 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 843 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
844 845
846 - def test_baldwin_synthetic(self):
847 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 848 849 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 850 851 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 852 """ 853 854 # The path to the data files. 855 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 856 857 # Create pipe 858 pipe_name = 'base pipe' 859 pipe_type = 'relax_disp' 860 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 861 862 # Create base pipe 863 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 864 865 # Generate the sequence. 866 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 867 868 # Define the isotope. 869 self.interpreter.spin.isotope('1H', spin_id='@H') 870 871 # Build the experiment IDs. 872 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 873 ncycs = [2, 4, 8, 10, 20, 40, 500] 874 ids = [] 875 for ncyc in ncycs: 876 ids.append('CPMG_%s' % ncyc) 877 878 print("\n\nThe experiment IDs are %s." % ids) 879 880 # Set up the metadata for the experiments. 881 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 882 sfrq = 200. * 1E6 883 884 # Total time of CPMG block. 885 Trelax = 0.04 886 887 # First set the 888 for i in range(len(ids)): 889 id = ids[i] 890 # Set the spectrometer frequency. 891 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 892 893 # Set the experiment type. 894 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 895 896 # Set the relaxation dispersion CPMG constant time delay T (in s). 897 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 898 899 # Set the relaxation dispersion CPMG frequencies. 900 ncyc = ncycs[i] 901 nu_cpmg = ncyc / Trelax 902 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 903 904 # Prepare for R2eff reading. 905 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 906 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 907 908 # Try reading the R2eff file. 909 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 910 911 # Check the global data. 912 data = [ 913 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 914 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 915 ['dispersion_points', len(ncycs)], 916 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 917 ['exp_type_list', ['SQ CPMG']], 918 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 919 ['spectrometer_frq_count', 1], 920 ['spectrometer_frq_list', [sfrq]], 921 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 922 ] 923 for name, value in data: 924 # Does it exist? 925 self.assert_(hasattr(cdp, name)) 926 927 # Check the object. 928 obj = getattr(cdp, name) 929 if not isinstance(data, dict): 930 self.assertEqual(obj, value) 931 932 # Check the global dictionary data. 933 else: 934 for id in ids: 935 self.assertEqual(obj[id], value[id]) 936 937 # Check the spin data. 938 n_data = [ 939 [ 50.000000, 10.367900, 0.1], 940 [ 100.000000, 10.146849, 0.1], 941 [ 200.000000, 9.765987, 0.1], 942 [ 250.000000, 9.409789, 0.1], 943 [ 500.000000, 5.829819, 0.1], 944 [ 1000.000000, 3.191928, 0.1], 945 [ 12500.000000, 2.008231, 0.1] 946 ] 947 for disp_point, value, error in n_data: 948 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 949 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 950 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 951 952 # Generate r20 key. 953 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 954 955 ## Now prepare for MODEL calculation. 956 MODEL = "B14" 957 958 # Change pipe. 959 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 960 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 961 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 962 963 # Then select model. 964 self.interpreter.relax_disp.select_model(model=MODEL) 965 966 # Store grid and minimisations results. 967 grid_results = [] 968 mini_results = [] 969 970 # The grid search size (the number of increments per dimension). 971 # If None, use the default values. 972 #GRID = None 973 GRID = 13 974 # Perform Grid Search. 975 if GRID: 976 # Set the R20 parameters in the default grid search using the minimum R2eff value. 977 # This speeds it up considerably. 978 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 979 980 # Then do grid search. 981 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 982 983 # If no Grid search, set the default values. 984 else: 985 for param in MODEL_PARAMS[MODEL]: 986 self.interpreter.value.set(param=param, index=None) 987 # Do a grid search, which will store the chi2 value. 988 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 989 990 # Store result. 991 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 992 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 993 994 ## Now do minimisation. 995 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 996 set_func_tol = 1e-10 997 set_max_iter = 1000 998 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 999 1000 # Store result. 1001 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1002 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1003 1004 # Print results. 1005 for i in range(len(grid_results)): 1006 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1007 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1008 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1009 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1010 1011 # Reference values from Baldwin.py. 1012 # Exchange rate = k+ + k- (s-1) 1013 kex = 1000. 1014 # Fractional population of excited state k+/kex 1015 pb = 0.01 1016 # deltaOmega in ppm 1017 dw_ppm = 2. 1018 #relaxation rate of ground (s-1) 1019 R2g = 2. 1020 #relaxation rate of excited (s-1) 1021 R2e = 2. 1022 1023 # Test the parameters which created the data. 1024 # This is for the 1H spin. 1025 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1026 1027 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1028 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1029 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1030 1031
1033 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1034 1035 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1036 """ 1037 1038 # The path to the data files. 1039 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1040 1041 # Create pipe 1042 pipe_name = 'base pipe' 1043 pipe_type = 'relax_disp' 1044 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1045 1046 # Create base pipe 1047 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1048 1049 # Generate the sequence. 1050 # Generate both a 1H spin, and 15N spin. 1051 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1052 1053 # Define the isotope. 1054 self.interpreter.spin.isotope('1H', spin_id='@H') 1055 1056 # Build the experiment IDs. 1057 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1058 ncycs = [2, 4, 8, 10, 20, 40, 500] 1059 ids = [] 1060 for ncyc in ncycs: 1061 ids.append('CPMG_%s' % ncyc) 1062 1063 print("\n\nThe experiment IDs are %s." % ids) 1064 1065 # Set up the metadata for the experiments. 1066 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1067 sfrq = 200. * 1E6 1068 1069 # Total time of CPMG block. 1070 Trelax = 0.04 1071 1072 # First set the 1073 for i in range(len(ids)): 1074 id = ids[i] 1075 # Set the spectrometer frequency. 1076 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1077 1078 # Set the experiment type. 1079 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1080 1081 # Set the relaxation dispersion CPMG constant time delay T (in s). 1082 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1083 1084 # Set the relaxation dispersion CPMG frequencies. 1085 ncyc = ncycs[i] 1086 nu_cpmg = ncyc / Trelax 1087 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1088 1089 # Prepare for R2eff reading. 1090 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1091 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1092 1093 # Try reading the R2eff file. 1094 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1095 1096 # Check the global data. 1097 data = [ 1098 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1099 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1100 ['dispersion_points', len(ncycs)], 1101 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1102 ['exp_type_list', ['SQ CPMG']], 1103 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1104 ['spectrometer_frq_count', 1], 1105 ['spectrometer_frq_list', [sfrq]], 1106 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1107 ] 1108 for name, value in data: 1109 # Does it exist? 1110 self.assert_(hasattr(cdp, name)) 1111 1112 # Check the object. 1113 obj = getattr(cdp, name) 1114 if not isinstance(data, dict): 1115 self.assertEqual(obj, value) 1116 1117 # Check the global dictionary data. 1118 else: 1119 for id in ids: 1120 self.assertEqual(obj[id], value[id]) 1121 1122 # Check the spin data. 1123 n_data = [ 1124 [ 50.000000, 10.286255, 0.1], 1125 [ 100.000000, 10.073083, 0.1], 1126 [ 200.000000, 9.692746, 0.1], 1127 [ 250.000000, 9.382441, 0.1], 1128 [ 500.000000, 6.312396, 0.1], 1129 [ 1000.000000, 3.957029, 0.1], 1130 [ 12500.000000, 2.880420, 0.1] 1131 ] 1132 for disp_point, value, error in n_data: 1133 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1134 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1135 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1136 1137 # Generate r20 key. 1138 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1139 1140 ## Now prepare for MODEL calculation. 1141 MODEL = "B14 full" 1142 1143 # Change pipe. 1144 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1145 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1146 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1147 1148 # Then select model. 1149 self.interpreter.relax_disp.select_model(model=MODEL) 1150 1151 # Store grid and minimisations results. 1152 grid_results = [] 1153 mini_results = [] 1154 clust_results = [] 1155 1156 # The grid search size (the number of increments per dimension). 1157 # If None, use the default values. 1158 #GRID = None 1159 GRID = 13 1160 # Perform Grid Search. 1161 if GRID: 1162 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1163 # This speeds it up considerably. 1164 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1165 1166 # Then do grid search. 1167 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1168 1169 # If no Grid search, set the default values. 1170 else: 1171 for param in MODEL_PARAMS[MODEL]: 1172 self.interpreter.value.set(param=param, index=None) 1173 # Do a grid search, which will store the chi2 value. 1174 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1175 1176 # Store result. 1177 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1178 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1179 1180 ## Now do minimisation. 1181 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1182 set_func_tol = 1e-11 1183 set_max_iter = 10000 1184 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1185 1186 # Store result. 1187 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1188 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1189 1190 print("\n# Now print before and after minimisation-\n") 1191 1192 # Print results. 1193 for i in range(len(grid_results)): 1194 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1195 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1196 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1197 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1198 1199 # Reference values from Baldwin.py. 1200 # Exchange rate = k+ + k- (s-1) 1201 kex = 1000. 1202 # Fractional population of excited state k+/kex 1203 pb = 0.01 1204 # deltaOmega in ppm 1205 dw_ppm = 2. 1206 #relaxation rate of ground (s-1) 1207 R2g = 2. 1208 #relaxation rate of excited (s-1) 1209 R2e = 100. 1210 1211 # Test the parameters which created the data. 1212 # This is for the 1H spin. 1213 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1214 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1215 1216 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1217 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1218 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1219 1220
1221 - def x_test_bmrb_sub_cpmg(self):
1222 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1223 This uses CPMG data from: 1224 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1225 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1226 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1227 """ 1228 1229 # Define path to data 1230 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1231 1232 # Read data. 1233 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1234 1235 # Set element 1236 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1237 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1238 # Rename molecule from None to 'HEWL' 1239 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1240 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1241 1242 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1243 print(spin_id) 1244 if resn == 'C': 1245 print(resi, resn) 1246 1247 # Select the thiol state of the system. 1248 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1249 self.interpreter.bmrb.thiol_state(state='not reported') 1250 1251 # relax_data.temp_calibration(ri_id=None, method=None) 1252 1253 # Call display of bmrb. 1254 self.interpreter.bmrb.display()
1255 1256
1258 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1259 1260 # Clear the data store. 1261 self.interpreter.reset() 1262 1263 # Load the state. 1264 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1265 self.interpreter.state.load(state, force=True) 1266 1267 # Model selection - to catch the failure. 1268 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1269 1270
1272 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1273 1274 # Clear the data store. 1275 self.interpreter.reset() 1276 1277 # Load the state. 1278 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1279 self.interpreter.state.load(state, force=True) 1280 1281 # Execute the auto-analysis (fast). 1282 relax_disp.Relax_disp.opt_func_tol = 1e-5 1283 relax_disp.Relax_disp.opt_max_iterations = 1000 1284 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1285 1286
1288 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1289 1290 # Clear the data store. 1291 self.interpreter.reset() 1292 1293 # Load the state. 1294 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1295 self.interpreter.state.load(state, force=True) 1296 1297 # Execute the auto-analysis (fast). 1298 relax_disp.Relax_disp.opt_func_tol = 1e-5 1299 relax_disp.Relax_disp.opt_max_iterations = 1000 1300 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1301 1302
1304 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1305 1306 # Clear the data store. 1307 self.interpreter.reset() 1308 1309 # Load the state. 1310 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1311 self.interpreter.state.load(state, force=True) 1312 1313 # Run the calculation. 1314 self.interpreter.minimise.calculate(verbosity=1)
1315 1316
1318 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1319 1320 # Clear the data store. 1321 self.interpreter.reset() 1322 1323 # Load the state. 1324 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1325 self.interpreter.state.load(state, force=True) 1326 1327 # Execute the auto-analysis (fast). 1328 relax_disp.Relax_disp.opt_func_tol = 1e-5 1329 relax_disp.Relax_disp.opt_max_iterations = 1000 1330 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1331 1332
1334 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1335 1336 # Clear the data store. 1337 self.interpreter.reset() 1338 1339 # Load the state. 1340 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1341 self.interpreter.state.load(state, force=True) 1342 1343 # Execute the auto-analysis (fast). 1344 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1345 relax_disp.Relax_disp.opt_func_tol = 1e-5 1346 relax_disp.Relax_disp.opt_max_iterations = 1000 1347 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=2, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1348 1349
1351 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1352 1353 # Base data setup. 1354 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1355 1356
1358 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1359 1360 # Base data setup. 1361 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1362 1363
1365 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1366 1367 # Base data setup. 1368 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1369 1370
1372 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1373 1374 # Base data setup. 1375 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1376 1377
1379 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1380 1381 # Clear the data store. 1382 self.interpreter.reset() 1383 1384 # Load the state. 1385 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1386 self.interpreter.state.load(state, force=True) 1387 1388 param = 'k_AB' 1389 1390 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1391 print(spin_id, spin.params) 1392 if param in spin.params: 1393 print(spin_id, spin.k_AB, spin.k_AB_err) 1394 1395 # Perform write. 1396 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1397 1398 1399 # Test the header of the value.write parameter r2. 1400 param = 'r2' 1401 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1402 1403 file = open(self.tmpdir+sep+'%s.out'%param) 1404 lines = file.readlines() 1405 file.close() 1406 1407 for i, line in enumerate(lines): 1408 # Make the string test 1409 line_split = line.split() 1410 print(line_split) 1411 1412 if len(line_split) > 1: 1413 # Break at parameter header. 1414 if line_split[0] == "#" and line_split[1] == 'mol_name': 1415 nr_split_header = len(line_split) 1416 nr_split_header_i = i 1417 break 1418 1419 # Call the line after. 1420 line_split_val = lines[nr_split_header_i + 1].split() 1421 print(line_split_val) 1422 1423 # Assert that the number of columns is equal, plus 1 for "#". 1424 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1425 1426 # Test the header of the value.write for parameter r2eff. 1427 param = 'r2eff' 1428 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1429 1430 file = open(self.tmpdir+sep+'%s.out'%param) 1431 lines = file.readlines() 1432 file.close() 1433 1434 for i, line in enumerate(lines): 1435 # Make the string test 1436 line_split = line.split() 1437 print(line_split) 1438 1439 if len(line_split) > 1: 1440 # Break at parameter header. 1441 if line_split[0] == "#" and line_split[1] == 'mol_name': 1442 nr_split_header = len(line_split) 1443 nr_split_header_i = i 1444 break 1445 1446 # Call the line after. 1447 line_split_val = lines[nr_split_header_i + 1].split() 1448 print(line_split_val) 1449 1450 # Assert that the number of columns is equal, plus 1 for "#". 1451 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1452 1453
1455 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1456 1457 # Define path to data 1458 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1459 1460 # Read data. 1461 self.interpreter.results.read(prev_data_path + sep + 'results') 1462 1463 # Now count number 1464 graph_nr = 1 1465 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1466 print("\nGraph nr %i" % graph_nr) 1467 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1468 print(exp_type, frq, offset, point, time) 1469 graph_nr += 1 1470 1471 ## Possibly do an error analysis. 1472 1473 # Check if intensity errors have already been calculated by the user. 1474 precalc = True 1475 for spin in spin_loop(skip_desel=True): 1476 # No structure. 1477 if not hasattr(spin, 'peak_intensity_err'): 1478 precalc = False 1479 break 1480 1481 # Determine if a spectrum ID is missing from the list. 1482 for id in cdp.spectrum_ids: 1483 if id not in spin.peak_intensity_err: 1484 precalc = False 1485 break 1486 1487 # Skip. 1488 if precalc: 1489 print("Skipping the error analysis as it has already been performed.") 1490 1491 else: 1492 # Loop over the spectrometer frequencies. 1493 for frq in loop_frq(): 1494 # Generate a list of spectrum IDs matching the frequency. 1495 ids = [] 1496 for id in cdp.spectrum_ids: 1497 # Check that the spectrometer frequency matches. 1498 match_frq = True 1499 if frq != None and cdp.spectrometer_frq[id] != frq: 1500 match_frq = False 1501 1502 # Add the ID. 1503 if match_frq: 1504 ids.append(id) 1505 1506 # Run the error analysis on the subset. 1507 self.interpreter.spectrum.error_analysis(subset=ids) 1508 1509 print("has_exponential_exp_type:", has_exponential_exp_type()) 1510 1511 model = 'R2eff' 1512 self.interpreter.relax_disp.select_model(model) 1513 1514 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1515 #delattr(spin, 'r2eff') 1516 #delattr(spin, 'r2eff_err') 1517 #delattr(spin, 'i0') 1518 #delattr(spin, 'i0_err') 1519 setattr(spin, 'r2eff', {}) 1520 setattr(spin, 'r2eff_err', {}) 1521 setattr(spin, 'i0', {}) 1522 setattr(spin, 'i0_err', {}) 1523 1524 # Do Grid Search 1525 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1526 1527 # Start dic. 1528 my_dic = {} 1529 1530 # Define counter for maximum elements in the numpy array list 1531 NE = 0 1532 NS = 1 1533 NM = 0 1534 NO = 0 1535 ND = 0 1536 NT = 0 1537 1538 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1539 # Save to counter. 1540 if ei > NE: 1541 NE = ei 1542 if mi > NM: 1543 NM = mi 1544 if oi > NO: 1545 NO = oi 1546 if di > ND: 1547 ND = di 1548 1549 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1550 # Save to counter. 1551 if ti > NT: 1552 NT = ti 1553 1554 # Add 1 to counter, since index start from 0. 1555 NE = NE + 1 1556 NM = NM + 1 1557 NO = NO + 1 1558 ND = ND + 1 1559 NT = NT + 1 1560 1561 # Make data array. 1562 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1563 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1564 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1565 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1566 param_key_list = [] 1567 1568 1569 # Loop over each spectrometer frequency and dispersion point. 1570 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1571 # Add key to dic. 1572 my_dic[spin_id] = {} 1573 1574 # Generate spin string. 1575 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1576 1577 # Loop over the parameters. 1578 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1579 1580 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1581 # Generate the param_key. 1582 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1583 1584 # Append key. 1585 param_key_list.append(param_key) 1586 1587 # Add key to dic. 1588 my_dic[spin_id][param_key] = {} 1589 1590 # Get the value. 1591 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1592 i0_value = getattr(cur_spin, 'i0')[param_key] 1593 1594 # Save to dic. 1595 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1596 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1597 1598 ## Now try do a line of best fit by least squares. 1599 # The peak intensities, errors and times. 1600 values = [] 1601 errors = [] 1602 times = [] 1603 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1604 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1605 values.append(value) 1606 1607 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1608 errors.append(error) 1609 times.append(time) 1610 1611 # Save to numpy arrays. 1612 values_arr[ei, 0, mi, oi, di, ti] = value 1613 errors_arr[ei, 0, mi, oi, di, ti] = error 1614 times_arr[ei, 0, mi, oi, di, ti] = time 1615 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1616 1617 # y= A exp(x * k) 1618 # w[i] = ln(y[i]) 1619 # int[i] = i0 * exp( - times[i] * r2eff); 1620 w = log(array(values)) 1621 x = - array(times) 1622 n = len(times) 1623 1624 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1625 a = 1./n * sum(w) - b * 1./n * sum(x) 1626 R2eff_est = b 1627 i0_est = exp(a) 1628 1629 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1630 my_dic[spin_id][param_key]['i0_est'] = i0_est 1631 1632 # Print value. 1633 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1634 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1635 1636 1637 # Do minimisation. 1638 set_func_tol = 1e-25 1639 set_max_iter = int(1e7) 1640 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1641 1642 # Loop over each spectrometer frequency and dispersion point. 1643 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1644 # Generate spin string. 1645 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1646 1647 # Loop over the parameters. 1648 print("Optimised parameters for spin: %s" % (spin_string)) 1649 1650 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1651 # Generate the param_key. 1652 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1653 1654 # Get the value. 1655 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1656 i0_value = getattr(cur_spin, 'i0')[param_key] 1657 1658 # Extract from dic. 1659 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1660 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1661 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1662 i0_est = my_dic[spin_id][param_key]['i0_est'] 1663 1664 # Print value. 1665 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1666 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1667 1668 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1669 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1670 1671 print(NE, NS, NM, NO, ND, NT) 1672 for param_key in param_key_list: 1673 print(" '%s'," % param_key) 1674 print(values_arr.shape) 1675 1676 # Save arrays to profiling. 1677 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1678 #save(data_path + "values_arr", values_arr) 1679 #save(data_path + "errors_arr", errors_arr) 1680 #save(data_path + "times_arr", times_arr) 1681 #save(data_path + "struct_arr", struct_arr) 1682 1683
1684 - def test_bug_atul_srivastava(self):
1685 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1686 shows it is exponential fitting, but only one time point is added per file. 1687 1688 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1689 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1690 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1691 1692 """ 1693 1694 # Data path. 1695 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1696 file = data_path + sep + 'bug_script.py' 1697 1698 # Run script. 1699 self.interpreter.script(file=file, dir=None) 1700 1701 # The grid search size (the number of increments per dimension). 1702 GRID_INC = 11 1703 1704 # Check-data. 1705 ################# 1706 1707 # Loop over spins, to see current setup. 1708 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1709 print(mol_name, resi, resn, spin_id) 1710 1711 # Loop over setup. 1712 for id in cdp.exp_type: 1713 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1714 1715 1716 # Manual minimisation. 1717 ################# 1718 if True: 1719 # Set the model. 1720 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1721 1722 # Check if intensity errors have already been calculated. 1723 check_intensity_errors() 1724 1725 # Calculate the R2eff values for the fixed relaxation time period data types. 1726 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1727 self.interpreter.minimise.calculate() 1728 1729 # Optimise the model. 1730 else: 1731 constraints = False 1732 min_algor = 'Newton' 1733 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1734 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1735 1736 # Inspect. 1737 if False: 1738 # Loop over attributes. 1739 par_attr_list = ['r2eff', 'i0'] 1740 1741 # Collect the estimation data. 1742 my_dic = {} 1743 param_key_list = [] 1744 est_keys = [] 1745 est_key = 'grid' 1746 est_keys.append(est_key) 1747 spin_id_list = [] 1748 1749 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1750 # Add key to dic. 1751 my_dic[spin_id] = {} 1752 1753 # Add key for estimate. 1754 my_dic[spin_id][est_key] = {} 1755 1756 # Add spin key to list. 1757 spin_id_list.append(spin_id) 1758 1759 # Generate spin string. 1760 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1761 1762 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1763 # Generate the param_key. 1764 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1765 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1766 1767 # Append key. 1768 param_key_list.append(param_key) 1769 1770 # Add key to dic. 1771 my_dic[spin_id][est_key][param_key] = {} 1772 1773 # Get the value. 1774 # Loop over err attributes. 1775 for par_attr in par_attr_list: 1776 if hasattr(cur_spin, par_attr): 1777 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1778 else: 1779 get_par_attr = 0.0 1780 1781 # Save to dic. 1782 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1783 1784 # Check number of values. 1785 values = [] 1786 errors = [] 1787 times = [] 1788 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1789 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1790 values.append(value) 1791 1792 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1793 errors.append(error) 1794 times.append(time) 1795 1796 # Save to dic. 1797 my_dic[spin_id][est_key][param_key]['values'] = values 1798 my_dic[spin_id][est_key][param_key]['errors'] = errors 1799 my_dic[spin_id][est_key][param_key]['times'] = times 1800 1801 # Analysis variables. 1802 ##################### 1803 1804 # The dispersion models. 1805 MODELS = ['R2eff', 'No Rex'] 1806 1807 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1808 MC_NUM = 10 1809 1810 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1811 MC_SIM_ALL_MODELS = False 1812 1813 # The results directory. 1814 RESULTS_DIR = ds.tmpdir 1815 1816 # The directory of results of an earlier analysis without clustering. 1817 PRE_RUN_DIR = None 1818 1819 # The model selection technique to use. 1820 MODSEL = 'AIC' 1821 1822 # The flag for only using numeric models in the final model selection. 1823 NUMERIC_ONLY = False 1824 1825 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1826 INSIGNIFICANCE = 1.0 1827 1828 # Auto-analysis execution. 1829 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1830 1831
1833 """Test data, where peak intensities are negative in CPMG 1834 1835 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1836 """ 1837 1838 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1839 1840 # Create the spins 1841 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1842 1843 # Name the isotope for field strength scaling. 1844 self.interpreter.spin.isotope(isotope='15N') 1845 1846 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1847 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1848 1849 # Loop over the spectra settings. 1850 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1851 1852 # Make empty ncyclist 1853 ncyclist = [] 1854 1855 i = 0 1856 for line in ncycfile: 1857 ncyc = line.split()[0] 1858 time_T2 = float(line.split()[1]) 1859 vcpmg = line.split()[2] 1860 set_sfrq = float(line.split()[3]) 1861 rmsd_err = float(line.split()[4]) 1862 1863 # Test if spectrum is a reference 1864 if float(vcpmg) == 0.0: 1865 vcpmg = None 1866 else: 1867 vcpmg = round(float(vcpmg), 3) 1868 1869 # Add ncyc to list 1870 ncyclist.append(int(ncyc)) 1871 1872 # Set the current spectrum id 1873 current_id = "Z_A%s"%(i) 1874 1875 # Set the current experiment type. 1876 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1877 1878 # Set the peak intensity errors, as defined as the baseplane RMSD. 1879 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1880 1881 # Set the NMR field strength of the spectrum. 1882 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1883 1884 # Relaxation dispersion CPMG constant time delay T (in s). 1885 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1886 1887 # Set the relaxation dispersion CPMG frequencies. 1888 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1889 1890 i += 1 1891 1892 # Specify the duplicated spectra. 1893 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 1894 1895 # Delete replicate spectrum 1896 #self.interpreter.spectrum.delete('Z_A15') 1897 1898 MODELS = [MODEL_R2EFF, MODEL_NOREX] 1899 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 1900 1901 results_dir = ds.tmpdir 1902 1903 # Execute 1904 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 1905 1906 # Check spin less R2eff points. 1907 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 1908 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 1909 if spin_id == ':4@N': 1910 self.assertEqual(len(cur_spin.r2eff), 14) 1911 else: 1912 self.assertEqual(len(cur_spin.r2eff), 15)
1913 1914
1915 - def test_check_missing_r1(self):
1916 """Test of the check_missing_r1() function.""" 1917 1918 # Set up some spins. 1919 self.setup_missing_r1_spins() 1920 1921 # Set variables. 1922 exp_type = 'R1rho' 1923 frq = 800.1 * 1E6 1924 1925 spectrum_id='test' 1926 1927 # Set an experiment type to the pipe. 1928 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 1929 1930 # Set a frequency to loop through. 1931 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 1932 1933 # Check R1 for DPL94. 1934 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1935 self.assertEqual(check_missing_r1_return, True) 1936 1937 # Check R1 for R2eff. 1938 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 1939 self.assertEqual(check_missing_r1_return, False) 1940 1941 # The path to the data files. 1942 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 1943 1944 # Now load some R1 data. 1945 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 1946 1947 # Check R1. 1948 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1949 self.assertEqual(check_missing_r1_return, False)
1950 1951
1953 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 1954 1955 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 1956 1957 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 1958 """ 1959 1960 # Reset. 1961 #self.interpreter.reset() 1962 1963 ## Set Experiments. 1964 model_create = 'B14' 1965 #model_create = 'NS CPMG 2-site expanded' 1966 model_analyse = 'NS CPMG 2-site 3D' 1967 1968 # Exp 1 1969 sfrq_1 = 599.8908617*1E6 1970 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 1971 time_T2_1 = 0.06 1972 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 1973 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1974 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1975 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 1976 1977 sfrq_2 = 499.8908617*1E6 1978 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 1979 time_T2_2 = 0.05 1980 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 1981 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1982 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1983 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 1984 1985 # Collect all exps 1986 exps = [exp_1, exp_2] 1987 1988 spins = [ 1989 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 1990 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 1991 ] 1992 1993 # Collect the data to be used. 1994 ds.data = [model_create, model_analyse, spins, exps] 1995 1996 # The tmp directory. None is the local directory. 1997 ds.tmpdir = ds.tmpdir 1998 1999 # The results directory. None is the local directory. 2000 #ds.resdir = None 2001 ds.resdir = ds.tmpdir 2002 2003 # Do r20_from_min_r2eff ?. 2004 ds.r20_from_min_r2eff = True 2005 2006 # Remove insignificant level. 2007 ds.insignificance = 0.0 2008 2009 # The grid search size (the number of increments per dimension). 2010 ds.GRID_INC = None 2011 2012 # The do clustering. 2013 ds.do_cluster = True 2014 2015 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2016 # The default value is 1e-25. 2017 ds.set_func_tol = 1e-1 2018 2019 # The maximum number of iterations. 2020 # The default value is 1e7. 2021 ds.set_max_iter = 1000 2022 2023 # The verbosity level. 2024 ds.verbosity = 1 2025 2026 # The rel_change WARNING level. 2027 ds.rel_change = 0.05 2028 2029 # The plot_curves. 2030 ds.plot_curves = False 2031 2032 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2033 ds.sherekhan_input = False 2034 2035 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2036 ds.opendx = False 2037 2038 # The set r2eff err. 2039 ds.r2eff_err = 0.1 2040 2041 # The print result info. 2042 ds.print_res = True 2043 2044 # Execute the script. 2045 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2046 2047 cur_spins = ds.data[2] 2048 # Compare results. 2049 for i in range(len(cur_spins)): 2050 res_name, res_num, spin_name, params = cur_spins[i] 2051 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2052 cur_spin = return_spin(cur_spin_id) 2053 2054 grid_params = ds.grid_results[i][3] 2055 2056 # Extract the clust results. 2057 min_params = ds.clust_results[i][3] 2058 # Now read the parameters. 2059 print("For spin: '%s'"%cur_spin_id) 2060 for mo_param in cur_spin.params: 2061 # The R2 is a dictionary, depending on spectrometer frequency. 2062 if isinstance(getattr(cur_spin, mo_param), dict): 2063 grid_r2 = grid_params[mo_param] 2064 min_r2 = min_params[mo_param] 2065 set_r2 = params[mo_param] 2066 for key, val in list(set_r2.items()): 2067 grid_r2_frq = grid_r2[key] 2068 min_r2_frq = min_r2[key] 2069 set_r2_frq = set_r2[key] 2070 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2071 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2072 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2073 if rel_change > ds.rel_change: 2074 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2075 print("###################################") 2076 2077 ## Make test on R2. 2078 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2079 else: 2080 grid_val = grid_params[mo_param] 2081 min_val = min_params[mo_param] 2082 set_val = params[mo_param] 2083 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2084 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2085 if rel_change > ds.rel_change: 2086 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2087 print("###################################") 2088 2089 ## Make test on parameters. 2090 if mo_param == 'dw': 2091 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2092 elif mo_param == 'kex': 2093 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2094 elif mo_param == 'pA': 2095 self.assertAlmostEqual(set_val, min_val, 2)
2096 2097
2099 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2100 2101 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2102 2103 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2104 """ 2105 2106 # Reset. 2107 #self.interpreter.reset() 2108 2109 ## Set Experiments. 2110 model_create = 'B14' 2111 #model_create = 'NS CPMG 2-site expanded' 2112 model_analyse = 'NS CPMG 2-site star' 2113 2114 # Exp 1 2115 sfrq_1 = 599.8908617*1E6 2116 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2117 time_T2_1 = 0.06 2118 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2119 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2120 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2121 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2122 2123 sfrq_2 = 499.8908617*1E6 2124 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2125 time_T2_2 = 0.05 2126 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2127 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2128 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2129 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2130 2131 # Collect all exps 2132 exps = [exp_1, exp_2] 2133 2134 spins = [ 2135 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2136 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2137 ] 2138 2139 # Collect the data to be used. 2140 ds.data = [model_create, model_analyse, spins, exps] 2141 2142 # The tmp directory. None is the local directory. 2143 ds.tmpdir = ds.tmpdir 2144 2145 # The results directory. None is the local directory. 2146 #ds.resdir = None 2147 ds.resdir = ds.tmpdir 2148 2149 # Do r20_from_min_r2eff ?. 2150 ds.r20_from_min_r2eff = True 2151 2152 # Remove insignificant level. 2153 ds.insignificance = 0.0 2154 2155 # The grid search size (the number of increments per dimension). 2156 ds.GRID_INC = None 2157 2158 # The do clustering. 2159 ds.do_cluster = True 2160 2161 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2162 # The default value is 1e-25. 2163 ds.set_func_tol = 1e-1 2164 2165 # The maximum number of iterations. 2166 # The default value is 1e7. 2167 ds.set_max_iter = 1000 2168 2169 # The verbosity level. 2170 ds.verbosity = 1 2171 2172 # The rel_change WARNING level. 2173 ds.rel_change = 0.05 2174 2175 # The plot_curves. 2176 ds.plot_curves = False 2177 2178 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2179 ds.sherekhan_input = False 2180 2181 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2182 ds.opendx = False 2183 2184 # The set r2eff err. 2185 ds.r2eff_err = 0.1 2186 2187 # The print result info. 2188 ds.print_res = True 2189 2190 # Execute the script. 2191 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2192 2193 cur_spins = ds.data[2] 2194 # Compare results. 2195 for i in range(len(cur_spins)): 2196 res_name, res_num, spin_name, params = cur_spins[i] 2197 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2198 cur_spin = return_spin(cur_spin_id) 2199 2200 grid_params = ds.grid_results[i][3] 2201 2202 # Extract the clust results. 2203 min_params = ds.clust_results[i][3] 2204 # Now read the parameters. 2205 print("For spin: '%s'"%cur_spin_id) 2206 for mo_param in cur_spin.params: 2207 # The R2 is a dictionary, depending on spectrometer frequency. 2208 if isinstance(getattr(cur_spin, mo_param), dict): 2209 grid_r2 = grid_params[mo_param] 2210 min_r2 = min_params[mo_param] 2211 set_r2 = params[mo_param] 2212 for key, val in list(set_r2.items()): 2213 grid_r2_frq = grid_r2[key] 2214 min_r2_frq = min_r2[key] 2215 set_r2_frq = set_r2[key] 2216 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2217 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2218 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2219 if rel_change > ds.rel_change: 2220 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2221 print("###################################") 2222 2223 ## Make test on R2. 2224 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2225 else: 2226 grid_val = grid_params[mo_param] 2227 min_val = min_params[mo_param] 2228 set_val = params[mo_param] 2229 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2230 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2231 if rel_change > ds.rel_change: 2232 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2233 print("###################################") 2234 2235 ## Make test on parameters. 2236 if mo_param == 'dw': 2237 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2238 elif mo_param == 'kex': 2239 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2240 elif mo_param == 'pA': 2241 self.assertAlmostEqual(set_val, min_val, 2)
2242 2243
2245 """Test synthetic cpmg data. 2246 2247 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2248 """ 2249 2250 # Reset. 2251 #self.interpreter.reset() 2252 2253 ## Set Experiments. 2254 model_create = 'NS CPMG 2-site 3D' 2255 #model_create = 'NS CPMG 2-site expanded' 2256 model_analyse = 'CR72' 2257 # Exp 1 2258 sfrq_1 = 599.8908617*1E6 2259 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2260 time_T2_1 = 0.06 2261 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2262 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2263 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2264 2265 sfrq_2 = 499.8908617*1E6 2266 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2267 time_T2_2 = 0.05 2268 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2269 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2270 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2271 2272 # Collect all exps 2273 exps = [exp_1, exp_2] 2274 2275 spins = [ 2276 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2277 ] 2278 2279 # Collect the data to be used. 2280 ds.data = [model_create, model_analyse, spins, exps] 2281 2282 # The tmp directory. None is the local directory. 2283 ds.tmpdir = ds.tmpdir 2284 2285 # The results directory. None is the local directory. 2286 #ds.resdir = None 2287 ds.resdir = ds.tmpdir 2288 2289 # Do r20_from_min_r2eff ?. 2290 ds.r20_from_min_r2eff = True 2291 2292 # Remove insignificant level. 2293 ds.insignificance = 0.0 2294 2295 # The grid search size (the number of increments per dimension). 2296 ds.GRID_INC = 8 2297 2298 # The do clustering. 2299 ds.do_cluster = False 2300 2301 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2302 # The default value is 1e-25. 2303 ds.set_func_tol = 1e-9 2304 2305 # The maximum number of iterations. 2306 # The default value is 1e7. 2307 ds.set_max_iter = 1000 2308 2309 # The verbosity level. 2310 ds.verbosity = 1 2311 2312 # The rel_change WARNING level. 2313 ds.rel_change = 0.05 2314 2315 # The plot_curves. 2316 ds.plot_curves = False 2317 2318 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2319 ds.sherekhan_input = False 2320 2321 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2322 ds.opendx = False 2323 2324 # The set r2eff err. 2325 ds.r2eff_err = 0.1 2326 2327 # The print result info. 2328 ds.print_res = False 2329 2330 # Execute the script. 2331 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2332 2333 cur_spins = ds.data[2] 2334 # Compare results. 2335 for i in range(len(cur_spins)): 2336 res_name, res_num, spin_name, params = cur_spins[i] 2337 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2338 cur_spin = return_spin(cur_spin_id) 2339 2340 grid_params = ds.grid_results[i][3] 2341 min_params = ds.min_results[i][3] 2342 # Now read the parameters. 2343 print("For spin: '%s'"%cur_spin_id) 2344 for mo_param in cur_spin.params: 2345 # The R2 is a dictionary, depending on spectrometer frequency. 2346 if isinstance(getattr(cur_spin, mo_param), dict): 2347 grid_r2 = grid_params[mo_param] 2348 min_r2 = min_params[mo_param] 2349 set_r2 = params[mo_param] 2350 for key, val in list(set_r2.items()): 2351 grid_r2_frq = grid_r2[key] 2352 min_r2_frq = min_r2[key] 2353 set_r2_frq = set_r2[key] 2354 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2355 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2356 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2357 if rel_change > ds.rel_change: 2358 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2359 print("###################################") 2360 2361 ## Make test on R2. 2362 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2363 else: 2364 grid_val = grid_params[mo_param] 2365 min_val = min_params[mo_param] 2366 set_val = params[mo_param] 2367 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2368 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2369 if rel_change > ds.rel_change: 2370 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2371 print("###################################") 2372 2373 ## Make test on parameters. 2374 if mo_param == 'dw': 2375 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2376 elif mo_param == 'kex': 2377 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2378 elif mo_param == 'pA': 2379 self.assertAlmostEqual(set_val, min_val, 3)
2380 2381
2383 """Test synthetic cpmg data. 2384 2385 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2386 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2387 """ 2388 2389 # Reset. 2390 #self.interpreter.reset() 2391 2392 ## Set Experiments. 2393 model_create = 'NS CPMG 2-site 3D' 2394 #model_create = 'NS CPMG 2-site expanded' 2395 model_analyse = 'B14' 2396 # Exp 1 2397 sfrq_1 = 599.8908617*1E6 2398 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2399 time_T2_1 = 0.06 2400 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2401 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2402 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2403 2404 sfrq_2 = 499.8908617*1E6 2405 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2406 time_T2_2 = 0.05 2407 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2408 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2409 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2410 2411 # Collect all exps 2412 exps = [exp_1, exp_2] 2413 2414 spins = [ 2415 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2416 ] 2417 2418 # Collect the data to be used. 2419 ds.data = [model_create, model_analyse, spins, exps] 2420 2421 # The tmp directory. None is the local directory. 2422 ds.tmpdir = ds.tmpdir 2423 2424 # The results directory. None is the local directory. 2425 #ds.resdir = None 2426 ds.resdir = ds.tmpdir 2427 2428 # Do r20_from_min_r2eff ?. 2429 ds.r20_from_min_r2eff = True 2430 2431 # Remove insignificant level. 2432 ds.insignificance = 0.0 2433 2434 # The grid search size (the number of increments per dimension). 2435 ds.GRID_INC = 8 2436 2437 # The do clustering. 2438 ds.do_cluster = False 2439 2440 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2441 # The default value is 1e-25. 2442 ds.set_func_tol = 1e-9 2443 2444 # The maximum number of iterations. 2445 # The default value is 1e7. 2446 ds.set_max_iter = 1000 2447 2448 # The verbosity level. 2449 ds.verbosity = 1 2450 2451 # The rel_change WARNING level. 2452 ds.rel_change = 0.05 2453 2454 # The plot_curves. 2455 ds.plot_curves = False 2456 2457 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2458 ds.sherekhan_input = False 2459 2460 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2461 ds.opendx = False 2462 2463 # The set r2eff err. 2464 ds.r2eff_err = 0.1 2465 2466 # The print result info. 2467 ds.print_res = False 2468 2469 # Execute the script. 2470 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2471 2472 cur_spins = ds.data[2] 2473 # Compare results. 2474 for i in range(len(cur_spins)): 2475 res_name, res_num, spin_name, params = cur_spins[i] 2476 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2477 cur_spin = return_spin(cur_spin_id) 2478 2479 grid_params = ds.grid_results[i][3] 2480 min_params = ds.min_results[i][3] 2481 # Now read the parameters. 2482 print("For spin: '%s'"%cur_spin_id) 2483 for mo_param in cur_spin.params: 2484 # The R2 is a dictionary, depending on spectrometer frequency. 2485 if isinstance(getattr(cur_spin, mo_param), dict): 2486 grid_r2 = grid_params[mo_param] 2487 min_r2 = min_params[mo_param] 2488 set_r2 = params[mo_param] 2489 for key, val in list(set_r2.items()): 2490 grid_r2_frq = grid_r2[key] 2491 min_r2_frq = min_r2[key] 2492 set_r2_frq = set_r2[key] 2493 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2494 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2495 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2496 if rel_change > ds.rel_change: 2497 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2498 print("###################################") 2499 2500 ## Make test on R2. 2501 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2502 else: 2503 grid_val = grid_params[mo_param] 2504 min_val = min_params[mo_param] 2505 set_val = params[mo_param] 2506 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2507 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2508 if rel_change > ds.rel_change: 2509 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2510 print("###################################") 2511 2512 ## Make test on parameters. 2513 if mo_param == 'dw': 2514 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2515 elif mo_param == 'kex': 2516 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2517 elif mo_param == 'pA': 2518 self.assertAlmostEqual(set_val, min_val, 6)
2519 2520
2522 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2523 2524 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2525 """ 2526 2527 # Reset. 2528 #self.interpreter.reset() 2529 2530 ## Set Experiments. 2531 model_create = 'NS CPMG 2-site 3D' 2532 #model_create = 'NS CPMG 2-site expanded' 2533 model_analyse = 'CR72' 2534 2535 # Exp 1 2536 sfrq_1 = 599.8908617*1E6 2537 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2538 time_T2_1 = 0.06 2539 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2540 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2541 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2542 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2543 2544 sfrq_2 = 499.8908617*1E6 2545 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2546 time_T2_2 = 0.05 2547 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2548 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2549 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2550 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2551 2552 # Collect all exps 2553 exps = [exp_1, exp_2] 2554 2555 spins = [ 2556 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2557 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2558 ] 2559 2560 # Collect the data to be used. 2561 ds.data = [model_create, model_analyse, spins, exps] 2562 2563 # The tmp directory. None is the local directory. 2564 ds.tmpdir = ds.tmpdir 2565 2566 # The results directory. None is the local directory. 2567 #ds.resdir = None 2568 ds.resdir = ds.tmpdir 2569 2570 # Do r20_from_min_r2eff ?. 2571 ds.r20_from_min_r2eff = True 2572 2573 # Remove insignificant level. 2574 ds.insignificance = 0.0 2575 2576 # The grid search size (the number of increments per dimension). 2577 ds.GRID_INC = 13 2578 2579 # The do clustering. 2580 ds.do_cluster = True 2581 2582 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2583 # The default value is 1e-25. 2584 ds.set_func_tol = 1e-8 2585 2586 # The maximum number of iterations. 2587 # The default value is 1e7. 2588 ds.set_max_iter = 10000 2589 2590 # The verbosity level. 2591 ds.verbosity = 1 2592 2593 # The rel_change WARNING level. 2594 ds.rel_change = 0.05 2595 2596 # The plot_curves. 2597 ds.plot_curves = False 2598 2599 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2600 ds.sherekhan_input = False 2601 2602 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2603 ds.opendx = False 2604 2605 # The set r2eff err. 2606 ds.r2eff_err = 0.1 2607 2608 # The print result info. 2609 ds.print_res = False 2610 2611 # Execute the script. 2612 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2613 2614 cur_spins = ds.data[2] 2615 # Compare results. 2616 for i in range(len(cur_spins)): 2617 res_name, res_num, spin_name, params = cur_spins[i] 2618 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2619 cur_spin = return_spin(cur_spin_id) 2620 2621 grid_params = ds.grid_results[i][3] 2622 2623 # Extract the clust results. 2624 min_params = ds.clust_results[i][3] 2625 # Now read the parameters. 2626 print("For spin: '%s'"%cur_spin_id) 2627 for mo_param in cur_spin.params: 2628 # The R2 is a dictionary, depending on spectrometer frequency. 2629 if isinstance(getattr(cur_spin, mo_param), dict): 2630 grid_r2 = grid_params[mo_param] 2631 min_r2 = min_params[mo_param] 2632 set_r2 = params[mo_param] 2633 for key, val in list(set_r2.items()): 2634 grid_r2_frq = grid_r2[key] 2635 min_r2_frq = min_r2[key] 2636 set_r2_frq = set_r2[key] 2637 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2638 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2639 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2640 if rel_change > ds.rel_change: 2641 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2642 print("###################################") 2643 2644 ## Make test on R2. 2645 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2646 else: 2647 grid_val = grid_params[mo_param] 2648 min_val = min_params[mo_param] 2649 set_val = params[mo_param] 2650 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2651 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2652 if rel_change > ds.rel_change: 2653 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2654 print("###################################") 2655 2656 ## Make test on parameters. 2657 if mo_param == 'dw': 2658 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2659 elif mo_param == 'kex': 2660 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2661 elif mo_param == 'pA': 2662 self.assertAlmostEqual(set_val, min_val, 2)
2663 2664
2666 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2667 2668 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2669 """ 2670 2671 # Reset. 2672 #self.interpreter.reset() 2673 2674 ## Set Experiments. 2675 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2676 model_analyse = 'CR72' 2677 # Exp 1 2678 sfrq_1 = 599.8908617*1E6 2679 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2680 time_T2_1 = 0.06 2681 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2682 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2683 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2684 2685 sfrq_2 = 499.8908617*1E6 2686 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2687 time_T2_2 = 0.05 2688 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2689 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2690 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2691 2692 # Collect all exps 2693 exps = [exp_1, exp_2] 2694 2695 spins = [ 2696 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2697 ] 2698 2699 # Collect the data to be used. 2700 ds.data = [model_create, model_analyse, spins, exps] 2701 2702 # The tmp directory. None is the local directory. 2703 ds.tmpdir = ds.tmpdir 2704 2705 # The results directory. None is the local directory. 2706 #ds.resdir = None 2707 ds.resdir = ds.tmpdir 2708 2709 # Do r20_from_min_r2eff ?. 2710 ds.r20_from_min_r2eff = True 2711 2712 # Remove insignificant level. 2713 ds.insignificance = 0.0 2714 2715 # The grid search size (the number of increments per dimension). 2716 ds.GRID_INC = None 2717 2718 # The do clustering. 2719 ds.do_cluster = False 2720 2721 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2722 # The default value is 1e-25. 2723 ds.set_func_tol = 1e-9 2724 2725 # The maximum number of iterations. 2726 # The default value is 1e7. 2727 ds.set_max_iter = 1000 2728 2729 # The verbosity level. 2730 ds.verbosity = 1 2731 2732 # The rel_change WARNING level. 2733 ds.rel_change = 0.05 2734 2735 # The plot_curves. 2736 ds.plot_curves = False 2737 2738 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2739 ds.sherekhan_input = False 2740 2741 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2742 ds.opendx = False 2743 2744 # The set r2eff err. 2745 ds.r2eff_err = 0.1 2746 2747 # The print result info. 2748 ds.print_res = False 2749 2750 # Execute the script. 2751 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2752 2753 # Get the spins. 2754 cur_spins = ds.data[2] 2755 2756 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2757 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2758 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2759 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2760 2761 # Copy R2eff, but not the original parameters 2762 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2763 2764 # Then select model. 2765 self.interpreter.relax_disp.select_model(model=model_analyse) 2766 2767 # Define dx.map settings. 2768 ds.dx_inc = 4 2769 ds.dx_params = ['dw', 'pA', 'kex'] 2770 2771 res_name, res_num, spin_name, params = cur_spins[0] 2772 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2773 cur_spin = return_spin(cur_spin_id) 2774 2775 print("Params for dx map is") 2776 print(ds.dx_params) 2777 print("Point param for dx map is") 2778 print(ds.dx_set_val) 2779 cur_model = model_analyse.replace(' ', '_') 2780 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2781 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2782 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2783 2784 ## Check for file creation 2785 # Set filepaths. 2786 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2787 map_net = ds.tmpdir+sep+file_name_map+".net" 2788 map_general = ds.tmpdir+sep+file_name_map+".general" 2789 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2790 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2791 2792 point_general = ds.tmpdir+sep+file_name_point+".general" 2793 point_point = ds.tmpdir+sep+file_name_point 2794 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2795 2796 # Test the files exists. 2797 self.assert_(access(map_cfg, F_OK)) 2798 self.assert_(access(map_net, F_OK)) 2799 self.assert_(access(map_general, F_OK)) 2800 self.assert_(access(map_par, F_OK)) 2801 self.assert_(access(map_plot, F_OK)) 2802 self.assert_(access(point_general, F_OK)) 2803 self.assert_(access(point_point, F_OK)) 2804 self.assert_(access(point_par, F_OK)) 2805 2806 # Open the files for testing. 2807 # Check the cfg file. 2808 print("\nChecking the dx map .cfg file.") 2809 res_file = [ 2810 '//'+"\n", 2811 '//'+"\n", 2812 '// time: Thu May 8 18:55:31 2014'+"\n", 2813 '//'+"\n", 2814 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2815 '//'+"\n", 2816 '//'+"\n", 2817 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2818 '// title: value = Control Panel'+"\n", 2819 '//'+"\n", 2820 '// workspace: width = 251, height = 142'+"\n", 2821 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2822 '//'+"\n", 2823 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2824 '// selections: maximum = 2, current = 0 '+"\n", 2825 '// option[0]: name = "Colour", value = 1'+"\n", 2826 '// option[1]: name = "Grey", value = 2'+"\n", 2827 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2828 '// label: value = Colour Selector'+"\n", 2829 '//'+"\n", 2830 '// node Image[3]:'+"\n", 2831 '// title: value = Surface'+"\n", 2832 '// depth: value = 24'+"\n", 2833 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2834 ] 2835 file = open(map_cfg, 'r') 2836 lines = file.readlines() 2837 file.close() 2838 for i in range(len(res_file)): 2839 # Skip time point 2840 if i == 2: 2841 continue 2842 self.assertEqual(res_file[i], lines[i]) 2843 2844 print("\nChecking the dx map .general file.") 2845 res_file = [ 2846 'file = CR72_map_1_N'+"\n", 2847 'grid = 5 x 5 x 5'+"\n", 2848 'format = ascii'+"\n", 2849 'interleaving = field'+"\n", 2850 'majority = row'+"\n", 2851 'field = data'+"\n", 2852 'structure = scalar'+"\n", 2853 'type = float'+"\n", 2854 'dependency = positions'+"\n", 2855 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2856 ''+"\n", 2857 'end'+"\n", 2858 ] 2859 file = open(map_general, 'r') 2860 lines = file.readlines() 2861 file.close() 2862 for i in range(len(res_file)): 2863 # Skip time point 2864 #if i == 2: 2865 # continue 2866 self.assertEqual(res_file[i], lines[i]) 2867 2868 print("\nChecking the dx point .general file.") 2869 res_file = [ 2870 'file = CR72_point_1_N'+"\n", 2871 'points = 2'+"\n", 2872 'format = ascii'+"\n", 2873 'interleaving = field'+"\n", 2874 'field = locations, field0'+"\n", 2875 'structure = 3-vector, scalar'+"\n", 2876 'type = float, float'+"\n", 2877 ''+"\n", 2878 'end'+"\n", 2879 ] 2880 file = open(point_general, 'r') 2881 lines = file.readlines() 2882 file.close() 2883 for i in range(len(res_file)): 2884 # Skip time point 2885 #if i == 2: 2886 # continue 2887 self.assertEqual(res_file[i], lines[i]) 2888 2889 print("\nChecking the dx point point file.") 2890 res_file = [ 2891 '0.8 3.92 0.39964 1'+"\n", 2892 '0.76981 3.9169 0.41353 1'+"\n", 2893 ] 2894 file = open(point_point, 'r') 2895 lines = file.readlines() 2896 file.close() 2897 for i in range(len(res_file)): 2898 # Skip time point 2899 #if i == 2: 2900 # continue 2901 self.assertEqual(res_file[i], lines[i]) 2902 2903 print("\nChecking the dx point par file.") 2904 res_file = [ 2905 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2906 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2907 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 2908 ] 2909 res_file2 = [ 2910 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 2911 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 2912 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 2913 ] # Python 2.5 and 3.1. 2914 file = open(point_par, 'r') 2915 lines = file.readlines() 2916 file.close() 2917 for i in range(len(res_file)): 2918 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 2919 self.assertEqual(res_file[i], lines[i]) 2920 2921 print("\nChecking the matplotlib surface plot file.") 2922 res_file = [ 2923 'from copy import deepcopy'+"\n", 2924 'import numpy as np'+"\n", 2925 'import scipy.interpolate'+"\n", 2926 'from numpy.ma import masked_where'+"\n", 2927 ''+"\n", 2928 'from mpl_toolkits.mplot3d import axes3d'+"\n", 2929 'import matplotlib.pyplot as plt'+"\n", 2930 'from matplotlib import cm'+"\n", 2931 ''+"\n", 2932 '# Open file and get header.'+"\n", 2933 'mapfile_name = "%s.par"'%file_name_map+"\n", 2934 'pointfile_name = "%s.par"'%file_name_point+"\n", 2935 ''+"\n", 2936 ] 2937 file = open(map_plot, 'r') 2938 lines = file.readlines() 2939 file.close() 2940 for i in range(len(res_file)): 2941 self.assertEqual(res_file[i], lines[i])
2942 2943
2945 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 2946 2947 # Reset. 2948 self.interpreter.reset() 2949 2950 # Load the base data. 2951 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 2952 self.interpreter.state.load(data_path+sep+'r2eff_values') 2953 2954 # The type. 2955 curve_type = get_curve_type(id='500_133.33.in') 2956 self.assertEqual(curve_type, 'fixed time')
2957 2958
2959 - def test_curve_type_r1rho_exponential(self, model=None):
2960 """Test the curve type detection using the 'M61' exponential test data.""" 2961 2962 # Reset. 2963 self.interpreter.reset() 2964 2965 # Load the base data. 2966 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 2967 self.interpreter.state.load(data_path+sep+'r2eff_values') 2968 2969 # The type. 2970 curve_type = get_curve_type(id='nu_2000_ncyc9') 2971 self.assertEqual(curve_type, 'exponential')
2972 2973
2974 - def test_curve_type_r1rho_fixed_time(self, model=None):
2975 """Test the curve type detection using the 'TP02' fixed time test data.""" 2976 2977 # Reset. 2978 self.interpreter.reset() 2979 2980 # Load the base data. 2981 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 2982 self.interpreter.state.load(data_path+sep+'r2eff_values') 2983 2984 # The type. 2985 curve_type = get_curve_type(id='nu_1000.0_500MHz') 2986 self.assertEqual(curve_type, 'fixed time')
2987 2988
2989 - def test_dpl94_data_to_dpl94(self):
2990 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 2991 2992 # Fixed time variable. 2993 ds.fixed = True 2994 2995 # Execute the script. 2996 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 2997 2998 # The original parameters. 2999 i0 = [100000.0, 20000.0] 3000 r1rho_prime = [2.25, 24.0] 3001 pA = 0.7 3002 kex = 1000.0 3003 delta_omega = [1.0, 2.0] 3004 phi_ex = [] 3005 for i in range(2): 3006 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3007 3008 # Switch to the 'DPL94' model data pipe, then check for each spin. 3009 self.interpreter.pipe.switch('DPL94 - relax_disp') 3010 spin_index = 0 3011 for spin, spin_id in spin_loop(return_id=True): 3012 # Printout. 3013 print("\nSpin %s." % spin_id) 3014 3015 # Check the fitted parameters. 3016 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3017 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3018 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3019 3020 # Increment the spin index. 3021 spin_index += 1
3022 3023
3024 - def test_dx_map_clustered(self):
3025 """Test making dx_map for residues under clustered calculation. 3026 3027 This uses CPMG data from: 3028 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3029 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3030 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3031 """ 3032 3033 # Define path to data 3034 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3035 3036 # Read data. 3037 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3038 3039 # Get residue of interest. 3040 cur_spin_id = ":%i@%s"%(52, 'N') 3041 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3042 3043 # Get the spin container. 3044 cur_spin = return_spin(cur_spin_id) 3045 3046 # Get the chi2 value 3047 pre_chi2 = cur_spin.chi2 3048 3049 # Then do a local minimisation. 3050 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3051 self.interpreter.minimise.calculate() 3052 3053 # Get the chi2 value after calculation. 3054 calc_chi2 = cur_spin.chi2 3055 3056 # Assert calculation is equal. 3057 self.assertAlmostEqual(pre_chi2, calc_chi2) 3058 3059 # Define dx.map settings. 3060 dx_inc = 2 3061 dx_inc_sides = dx_inc / 2 3062 3063 dx_params = ['dw', 'pA', 'kex'] 3064 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3065 3066 print("Params for dx map is") 3067 print(dx_params) 3068 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3069 print(dx_point_clustered_min) 3070 3071 # Define file_names. 3072 cur_model = 'CR72' 3073 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3074 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3075 3076 # Step-size of parameter is 10 % 3077 param_delta = 0.1 3078 3079 # Determine bounds for lower and upper 3080 lower = [] 3081 upper = [] 3082 for i, param_val in enumerate(dx_point_clustered_min): 3083 param = dx_params[i] 3084 step_val = param_delta * param_val 3085 step_length = step_val * dx_inc_sides 3086 3087 # Calculate value 3088 low_val = param_val - step_length 3089 lower.append(low_val) 3090 3091 upp_val = param_val + step_length 3092 upper.append(upp_val) 3093 3094 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3095 3096 # If the number of increments are 2, there will be 3 point calculations per parameter. 3097 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3098 dx_param_indexes = dx_inc + 1 3099 dx_point_index = dx_inc_sides + 1 3100 3101 # Find the line number. 3102 line = 1 3103 for i in range(1, dx_param_indexes + 1): 3104 for j in range(1, dx_param_indexes + 1): 3105 for k in range(1, dx_param_indexes + 1): 3106 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3107 line_chi2 = line 3108 # Add to line counter. 3109 line += 1 3110 3111 # Define temporary folder. 3112 result_dir = self.tmpdir 3113 3114 # For testing. 3115 #result_dir = None 3116 #lower = None 3117 #upper = None 3118 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3119 3120 3121 # Then do the map. 3122 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3123 3124 # Print where to locate values. 3125 nr_chi2_val = dx_param_indexes**3 3126 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3127 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3128 3129 ## Check for file creation 3130 # Set filepaths. 3131 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3132 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3133 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3134 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3135 3136 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3137 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3138 3139 # Test the files exists. 3140 self.assert_(access(map_cfg, F_OK)) 3141 self.assert_(access(map_net, F_OK)) 3142 self.assert_(access(map_general, F_OK)) 3143 self.assert_(access(point_general, F_OK)) 3144 self.assert_(access(point_point, F_OK)) 3145 3146 # Open the file, and assert the chi2 value is as expected. 3147 get_data = extract_data(file=map_name) 3148 3149 # Extract line 0, column 0. 3150 test = float(get_data[line_chi2-1][0]) 3151 3152 # Assert. 3153 self.assertAlmostEqual(test, pre_chi2, 6)
3154 3155
3157 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3158 3159 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3160 3161 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3162 """ 3163 3164 # Define path to data 3165 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3166 3167 # Read data. 3168 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3169 3170 # Get residue of interest. 3171 cur_spin_id = ":%i@%s"%(65, 'N') 3172 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3173 3174 # Get the spin container. 3175 cur_spin = return_spin(cur_spin_id) 3176 3177 # Get the chi2 value 3178 pre_chi2 = cur_spin.chi2 3179 3180 # Then do a local minimisation. 3181 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3182 self.interpreter.minimise.calculate() 3183 3184 # Get the chi2 value after calculation. 3185 calc_chi2 = cur_spin.chi2 3186 3187 # Assert calculation is equal. 3188 self.assertAlmostEqual(pre_chi2, calc_chi2) 3189 3190 # Define dx.map settings. 3191 dx_inc = 2 3192 dx_params = ['dw', 'k_AB', 'r2a'] 3193 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3194 3195 print("Params for dx map is") 3196 print(dx_params) 3197 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3198 print(dx_point_clustered_min) 3199 3200 # Define file_names. 3201 cur_model = 'TSMFK01' 3202 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3203 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3204 3205 # Determine bounds for lower and upper 3206 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3207 upper = [19.0, 2.4, 9.5] 3208 3209 # Define temporary folder. 3210 result_dir = self.tmpdir 3211 3212 # For testing. 3213 #result_dir = None 3214 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3215 3216 # Then do the map. 3217 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3218 3219 # Print where to locate values. 3220 nr_chi2_val = (dx_inc + 1)**3 3221 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3222 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3223 3224 ## Check for file creation 3225 # Set filepaths. 3226 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3227 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3228 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3229 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3230 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3231 3232 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3233 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3234 3235 # Test the files exists. 3236 self.assert_(access(map_cfg, F_OK)) 3237 self.assert_(access(map_net, F_OK)) 3238 self.assert_(access(map_general, F_OK)) 3239 self.assert_(access(map_par, F_OK)) 3240 self.assert_(access(point_general, F_OK)) 3241 self.assert_(access(point_point, F_OK)) 3242 3243 print("\nParams for dx map is") 3244 print(dx_params) 3245 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3246 print(dx_point_clustered_min, "\n") 3247 3248 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3249 get_data = extract_data(file=map_par) 3250 3251 # Extract line 1, column 9. 3252 test = float(get_data[1][9]) 3253 3254 # Print data if map contain a lower value than the global minimised value. 3255 if test < pre_chi2: 3256 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3257 for line in get_data: 3258 print(line)
3259 3260 # Assert that the initial global chi2 is lower than the map value. 3261 3262 # The following test was taken out, since this a particular interesting case. 3263 # There exist a double minimum, where relax has not found the global minimum. 3264 # This is due to not grid searching for R2A, but using the minimum 3265 #self.assert_(pre_chi2 < test) 3266 3267
3268 - def test_estimate_r2eff_err(self):
3269 """Test the user function for estimating R2eff errors from exponential curve fitting. 3270 3271 This follows Task 7822. 3272 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3273 3274 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3275 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3276 """ 3277 3278 # Cluster residues 3279 cluster_ids = [ 3280 ":13@N", 3281 ":15@N", 3282 ":16@N", 3283 ":25@N", 3284 ":26@N", 3285 ":28@N", 3286 ":39@N", 3287 ":40@N", 3288 ":41@N", 3289 ":43@N", 3290 ":44@N", 3291 ":45@N", 3292 ":49@N", 3293 ":52@N", 3294 ":53@N"] 3295 3296 # Load the data. 3297 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3298 3299 # The dispersion models. 3300 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3301 3302 # The grid search size (the number of increments per dimension). 3303 GRID_INC = None 3304 3305 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3306 MC_NUM = 3 3307 3308 # Model selection technique. 3309 MODSEL = 'AIC' 3310 3311 # Execute the auto-analysis (fast). 3312 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3313 OPT_FUNC_TOL = 1e-25 3314 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3315 OPT_MAX_ITERATIONS = 10000000 3316 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3317 3318 result_dir_name = ds.tmpdir 3319 3320 # Make all spins free 3321 for curspin in cluster_ids: 3322 self.interpreter.relax_disp.cluster('free spins', curspin) 3323 # Shut them down 3324 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3325 3326 # Select only a subset of spins for global fitting 3327 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3328 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3329 3330 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3331 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3332 3333 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3334 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3335 3336 # Set the model. 3337 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3338 3339 # Check if intensity errors have already been calculated. 3340 check_intensity_errors() 3341 3342 # Do a grid search. 3343 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3344 3345 # Minimise. 3346 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3347 3348 # Estimate R2eff errors. 3349 self.interpreter.relax_disp.r2eff_err_estimate() 3350 3351 r1_fit = True 3352 3353 # Run the analysis. 3354 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3355 3356 # Verify the data. 3357 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3358 3359
3361 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3362 3363 This follows Task 7822. 3364 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3365 3366 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3367 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3368 """ 3369 3370 # Cluster residues 3371 cluster_ids = [ 3372 ":13@N", 3373 ":15@N", 3374 ":16@N", 3375 ":25@N", 3376 ":26@N", 3377 ":28@N", 3378 ":39@N", 3379 ":40@N", 3380 ":41@N", 3381 ":43@N", 3382 ":44@N", 3383 ":45@N", 3384 ":49@N", 3385 ":52@N", 3386 ":53@N"] 3387 3388 # Load the data. 3389 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3390 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3391 3392 # Set pipe name, bundle and type. 3393 pipe_name = 'base pipe' 3394 pipe_bundle = 'relax_disp' 3395 pipe_type = 'relax_disp' 3396 3397 # Create the data pipe. 3398 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3399 3400 file = data_path + '1_setup_r1rho_GUI.py' 3401 self.interpreter.script(file=file, dir=None) 3402 3403 # The dispersion models. 3404 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3405 3406 # The grid search size (the number of increments per dimension). 3407 GRID_INC = None 3408 3409 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3410 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3411 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3412 EXP_MC_NUM = -1 3413 3414 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3415 MC_NUM = 3 3416 3417 # Model selection technique. 3418 MODSEL = 'AIC' 3419 3420 # Execute the auto-analysis (fast). 3421 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3422 OPT_FUNC_TOL = 1e-25 3423 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3424 OPT_MAX_ITERATIONS = 10000000 3425 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3426 3427 # Make all spins free 3428 #for curspin in cluster_ids: 3429 # self.interpreter.relax_disp.cluster('free spins', curspin) 3430 # # Shut them down 3431 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3432 3433 # Make all spins free 3434 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3435 3436 # Select only a subset of spins for global fitting 3437 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3438 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3439 3440 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3441 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3442 3443 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3444 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3445 3446 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3447 print(spin_id) 3448 3449 result_dir_name = self.tmpdir 3450 r1_fit = True 3451 3452 # Run the analysis. 3453 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3454 3455 # Verify the data. 3456 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3457 3458
3460 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3461 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3462 3463 This follows Task 7822. 3464 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3465 3466 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3467 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3468 3469 NOTE: The difference in the methods was due to a bug in relax! 3470 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3471 3472 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3473 """ 3474 3475 # Define data path. 3476 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3477 3478 # Create pipe. 3479 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3480 3481 # Read results for 2000 MC simulations. 3482 self.interpreter.results.read(prev_data_path + sep + 'results') 3483 3484 # Start dic. 3485 my_dic = {} 3486 param_key_list = [] 3487 3488 # Do boot strapping ? 3489 do_boot = True 3490 if do_boot: 3491 min_algor = 'Newton' 3492 min_options = () 3493 sim_boot = 200 3494 scaling_list = [1.0, 1.0] 3495 3496 # First check sim values. 3497 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3498 # Add key to dic. 3499 my_dic[spin_id] = {} 3500 3501 # Loop over sim. 3502 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3503 # Loop over all exp type. 3504 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3505 # Generate the param_key. 3506 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3507 r2eff_sim_point = r2eff_sim[param_key] 3508 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3509 3510 # Assert point are higher than 0.0. 3511 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3512 #print(point_info) 3513 self.assert_(r2eff_sim_point > 0.0) 3514 self.assert_(i0_sim_point > 0.0) 3515 3516 # Get the data. 3517 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3518 # Generate spin string. 3519 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3520 3521 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3522 # Generate the param_key. 3523 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3524 3525 # Loop over all sim, and collect data. 3526 r2eff_sim_l = [] 3527 i0_sim_l = [] 3528 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3529 i0_sim = cur_spin.i0_sim[i] 3530 3531 r2eff_sim_i = r2eff_sim[param_key] 3532 r2eff_sim_l.append(r2eff_sim_i) 3533 i0_sim_i = i0_sim[param_key] 3534 i0_sim_l.append(i0_sim_i) 3535 3536 # Take the standard deviation of all values. 3537 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3538 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3539 3540 # Append key. 3541 param_key_list.append(param_key) 3542 3543 # Add key to dic. 3544 my_dic[spin_id][param_key] = {} 3545 3546 # Get the value. 3547 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3548 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3549 i0 = getattr(cur_spin, 'i0')[param_key] 3550 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3551 3552 # Save to dic. 3553 my_dic[spin_id][param_key]['r2eff'] = r2eff 3554 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3555 my_dic[spin_id][param_key]['i0'] = i0 3556 my_dic[spin_id][param_key]['i0_err'] = i0_err 3557 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3558 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3559 3560 # Assert values are equal 3561 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3562 self.assertAlmostEqual(i0_sim_err, i0_err) 3563 3564 if do_boot: 3565 values = [] 3566 errors = [] 3567 times = [] 3568 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3569 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3570 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3571 times.append(time) 3572 3573 # Convert to numpy array. 3574 values = asarray(values) 3575 errors = asarray(errors) 3576 times = asarray(times) 3577 3578 R_m_sim_l = [] 3579 I0_m_sim_l = [] 3580 for j in range(sim_boot): 3581 if j in range(0, 100000, 100): 3582 print("Simulation %i"%j) 3583 # Start minimisation. 3584 3585 # Produce errors 3586 I_err = [] 3587 for j, error in enumerate(errors): 3588 I_error = gauss(values[j], error) 3589 I_err.append(I_error) 3590 # Convert to numpy array. 3591 I_err = asarray(I_err) 3592 3593 x0 = [r2eff, i0] 3594 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3595 3596 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3597 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3598 R_m_sim_l.append(R_m_sim_j) 3599 I0_m_sim_l.append(I0_m_sim_j) 3600 3601 # Get stats on distribution. 3602 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3603 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3604 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3605 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3606 3607 3608 # A new data pipe. 3609 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3610 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3611 3612 # Delete old errors. 3613 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3614 delattr(cur_spin, 'r2eff_err') 3615 delattr(cur_spin, 'i0_err') 3616 3617 # Set the model. 3618 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3619 3620 # Estimate R2eff and errors. 3621 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3622 3623 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3624 # Generate spin string. 3625 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3626 3627 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3628 # Generate the param_key. 3629 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3630 3631 # Get the value. 3632 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3633 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3634 i0_est = getattr(cur_spin, 'i0')[param_key] 3635 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3636 3637 # Get from dic. 3638 r2eff = my_dic[spin_id][param_key]['r2eff'] 3639 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3640 i0 = my_dic[spin_id][param_key]['i0'] 3641 i0_err = my_dic[spin_id][param_key]['i0_err'] 3642 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3643 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3644 3645 if do_boot: 3646 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3647 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3648 else: 3649 r2eff_boot_err = 0.0 3650 i0_boot_err = 0.0 3651 3652 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3653 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3654 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3655 3656 3657 # Now do it manually. 3658 estimate_r2eff(method='scipy.optimize.leastsq') 3659 3660 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3661 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3662 3663 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3664 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3665 3666 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3667 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3668 3669 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3670 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3671 3672 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3673 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3674 3675 3676
3677 - def test_exp_fit(self):
3678 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3679 3680 # Execute the script. 3681 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3682 3683 # The original exponential curve parameters. 3684 res_data = [ 3685 [15., 10., 20000., 25000.], 3686 [12., 11., 50000., 51000.], 3687 [17., 9., 100000., 96000.] 3688 ] 3689 3690 # List of parameters which do not belong to the model. 3691 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3692 3693 # Checks for each residue. 3694 for i in range(len(res_data)): 3695 # Printout. 3696 print("\nResidue number %s." % (i+1)) 3697 3698 # Check the fitted parameters. 3699 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3700 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3701 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3702 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3703 3704 # Check the simulation errors. 3705 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3706 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3707 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3708 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3709 3710 # Check that certain parameters are not present. 3711 for param in blacklist: 3712 print("\tChecking for the absence of the '%s' parameter." % param) 3713 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3714 3715 # Check the clustering information. 3716 self.assert_(hasattr(cdp, 'clustering')) 3717 keys = ['free spins', 'cluster'] 3718 for key in keys: 3719 self.assert_(key in cdp.clustering) 3720 self.assert_('test' not in cdp.clustering) 3721 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3722 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3723 3724
3725 - def test_finite_value(self):
3726 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3727 3728 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3729 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3730 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3731 3732 scaling_list = [1.0, 1.0] 3733 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3734 3735 R = - 500. 3736 I0 = 1000. 3737 params = [R, I0] 3738 3739 chi2 = model.func(params) 3740 3741 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3742 self.assertNotEqual(chi2, inf)
3743 3744
3745 - def test_hansen_catia_input(self):
3746 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3747 3748 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3749 """ 3750 3751 # Load the R2eff results file. 3752 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3753 self.interpreter.results.read(file_name) 3754 self.interpreter.deselect.spin(':4') 3755 3756 # The spin isotopes. 3757 self.interpreter.spin.isotope("15N") 3758 3759 # Generate the input files. 3760 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3761 3762 # Check the r2eff set files. 3763 print("\nChecking the R2eff input set files.") 3764 files = ['data_set_500.inp', 'data_set_500.inp'] 3765 for file in files: 3766 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3767 data_set_500 = [ 3768 "ID=500\n", 3769 "Sfrq = 500\n", 3770 "Temperature = 0.0\n", 3771 "Nucleus = N15\n", 3772 "Couplednucleus = H1\n", 3773 "Time_equil = 0.0\n", 3774 "Pwx_cp = 0.0\n", 3775 "Taub = 0.0\n", 3776 "Time_T2 = 0.03\n", 3777 "Xcar = 0.0\n", 3778 "Seqfil = CW_CPMG\n", 3779 "Minerror = (2.%;0.5/s)\n", 3780 "Basis = (Iph_7)\n", 3781 "Format = (0;1;2)\n", 3782 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3783 "Data = (\n", 3784 " [70N;spin_70_N_500.cpmg];\n", 3785 " [71N;spin_71_N_500.cpmg];\n", 3786 ")\n", 3787 ] 3788 file = open(ds.tmpdir+sep+files[0]) 3789 lines = file.readlines() 3790 file.close() 3791 for i in range(len(data_set_500)): 3792 # Skip the data directory, as this is a random file name. 3793 if i == 14: 3794 continue 3795 3796 self.assertEqual(data_set_500[i], lines[i]) 3797 3798 # Check the r2eff files. 3799 print("\nChecking the R2eff input files.") 3800 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3801 for file in files: 3802 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3803 spin_70_N_500 = [ 3804 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3805 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3806 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3807 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3808 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3809 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3810 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3811 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3812 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3813 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3814 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3815 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3816 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3817 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3818 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3819 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3820 ] 3821 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3822 lines = file.readlines() 3823 file.close() 3824 for i in range(len(lines)): 3825 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3826 for i in range(len(spin_70_N_500)): 3827 self.assertEqual(spin_70_N_500[i], lines[i]) 3828 3829 # Check the main file. 3830 print("\nChecking the main CATIA execution file.") 3831 main_file = [ 3832 "ReadDataset(data_set_500.inp)\n", 3833 "ReadDataset(data_set_800.inp)\n", 3834 "ReadParam_Global(ParamGlobal.inp)\n", 3835 "ReadParam_Local(ParamSet1.inp)\n", 3836 "\n", 3837 "FreeLocalParam(all;Omega;false)\n", 3838 "FreeLocalParam(all;R1iph_500;false)\n", 3839 "FreeLocalParam(all;R1iph_800;false)\n", 3840 "\n", 3841 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3842 "\n", 3843 "PrintParam(output/GlobalParam.fit;global)\n", 3844 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3845 "PrintData(output/)\n", 3846 "\n", 3847 "ChiSq(all;all)\n", 3848 "exit(0)\n" 3849 ] 3850 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3851 lines = file.readlines() 3852 file.close() 3853 for i in range(len(main_file)): 3854 self.assertEqual(main_file[i], lines[i])
3855 3856
3858 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3859 3860 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3861 """ 3862 3863 # Set the model. 3864 ds.models = [ 3865 MODEL_NOREX, 3866 MODEL_LM63, 3867 MODEL_CR72, 3868 MODEL_IT99 3869 ] 3870 3871 # Execute the script. 3872 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3873 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3874 3875 # The R20 keys. 3876 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3877 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3878 3879 # The 'No Rex' model checks. 3880 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3881 spin70 = return_spin(":70") 3882 spin71 = return_spin(":71") 3883 print("\n\nOptimised parameters:\n") 3884 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3885 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3886 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3887 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3888 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3889 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3890 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3891 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3892 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3893 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3894 3895 # The 'LM63' model checks. 3896 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3897 spin70 = return_spin(":70") 3898 spin71 = return_spin(":71") 3899 print("\n\nOptimised parameters:\n") 3900 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3901 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3902 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3903 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3904 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3905 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3906 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3907 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3908 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3909 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3910 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3911 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3912 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3913 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3914 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3915 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3916 3917 # The 'CR72' model checks. 3918 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3919 spin70 = return_spin(":70") 3920 spin71 = return_spin(":71") 3921 print("\n\nOptimised parameters:\n") 3922 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3923 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3924 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3925 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3926 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3927 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3928 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3929 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3930 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3931 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3932 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3933 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3934 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3935 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3936 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3937 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3938 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3939 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3940 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
3941 3942
3944 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3945 3946 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3947 """ 3948 3949 # Set the model and numeric flag. 3950 ds.models = [ 3951 MODEL_NOREX, 3952 MODEL_CR72, 3953 MODEL_NS_CPMG_2SITE_EXPANDED 3954 ] 3955 ds.numeric_only = True 3956 3957 # Execute the script. 3958 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3959 3960 # The R20 keys. 3961 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3962 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3963 3964 # The 'No Rex' model checks. 3965 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3966 spin70 = return_spin(":70") 3967 spin71 = return_spin(":71") 3968 print("\n\nOptimised parameters:\n") 3969 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3970 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3971 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3972 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3973 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3974 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3975 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 3976 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3977 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3978 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 3979 3980 # The 'CR72' model checks. 3981 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3982 spin70 = return_spin(":70") 3983 spin71 = return_spin(":71") 3984 print("\n\nOptimised parameters:\n") 3985 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3986 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3987 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3988 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3989 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3990 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3991 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3992 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3993 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3994 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3995 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3996 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3997 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3998 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3999 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4000 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4001 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4002 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4003 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4004 4005 # The 'NS CPMG 2-site expanded' model checks. 4006 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4007 spin70 = return_spin(":70") 4008 spin71 = return_spin(":71") 4009 print("\n\nOptimised parameters:\n") 4010 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4011 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4012 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4013 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4014 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4015 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4016 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4017 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4018 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4019 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4020 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4021 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4022 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4023 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4024 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4025 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4026 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4027 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4028 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4029 4030 # The final data pipe checks. 4031 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4032 spin70 = return_spin(":70") 4033 spin71 = return_spin(":71") 4034 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4035 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4036 4037
4039 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4040 4041 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4042 """ 4043 4044 # Set the model. 4045 ds.models = [ 4046 MODEL_NOREX, 4047 MODEL_LM63, 4048 MODEL_CR72, 4049 MODEL_IT99 4050 ] 4051 4052 # Execute the script. 4053 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4054 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4055 4056 # The R20 keys. 4057 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4058 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4059 4060 # The 'No Rex' model checks. 4061 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4062 spin70 = return_spin(":70") 4063 spin71 = return_spin(":71") 4064 print("\n\nOptimised parameters:\n") 4065 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4066 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4067 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4068 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4069 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4070 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4071 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4072 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4073 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4074 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4075 4076 # The 'LM63' model checks. 4077 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4078 spin70 = return_spin(":70") 4079 spin71 = return_spin(":71") 4080 print("\n\nOptimised parameters:\n") 4081 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4082 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4083 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4084 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4085 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4086 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4087 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4088 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4089 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4090 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4091 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4092 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4093 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4094 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4095 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4096 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4097 4098 # The 'CR72' model checks. 4099 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4100 spin70 = return_spin(":70") 4101 spin71 = return_spin(":71") 4102 print("\n\nOptimised parameters:\n") 4103 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4104 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4105 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4106 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4107 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4108 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4109 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4110 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4111 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4112 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4113 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4114 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4115 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4116 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4117 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4118 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4119 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4120 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4121 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4122 4123
4125 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4126 4127 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4128 """ 4129 4130 # Set the model. 4131 ds.models = [ 4132 MODEL_R2EFF, 4133 MODEL_NOREX, 4134 MODEL_CR72, 4135 MODEL_NS_CPMG_2SITE_EXPANDED 4136 ] 4137 4138 # Execute the script. 4139 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4140 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4141 4142 # The R20 keys. 4143 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4144 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4145 4146 # The 'No Rex' model checks. 4147 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4148 spin4 = return_spin(":4") 4149 spin70 = return_spin(":70") 4150 spin71 = return_spin(":71") 4151 print("\n\nOptimised parameters:\n") 4152 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4153 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4154 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4155 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4156 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4157 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4158 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4159 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4160 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4161 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4162 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4163 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4164 4165 # The 'CR72' model checks. 4166 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4167 spin4 = return_spin(":4") 4168 spin70 = return_spin(":70") 4169 spin71 = return_spin(":71") 4170 print("\n\nOptimised parameters:\n") 4171 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4172 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4173 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4174 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4175 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4176 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4177 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4178 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4179 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4180 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4181 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4182 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4183 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4184 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4185 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4186 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4187 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4188 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4189 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4190 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4191 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4192 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4193 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4194 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4195 4196
4198 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4199 4200 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4201 """ 4202 4203 # Base data setup. 4204 self.setup_hansen_cpmg_data(model='CR72') 4205 4206 # Alias the spins. 4207 spin70 = return_spin(":70") 4208 spin71 = return_spin(":71") 4209 4210 # The R20 keys. 4211 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4212 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4213 4214 # Set the initial parameter values. 4215 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4216 spin70.pA = 0.9 4217 spin70.dw = 6.0 4218 spin70.kex = 1500.0 4219 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4220 spin71.pA = 0.9 4221 spin71.dw = 4.0 4222 spin71.kex = 1900.0 4223 4224 # Low precision optimisation. 4225 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4226 4227 # Printout. 4228 print("\n\nOptimised parameters:\n") 4229 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4230 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4231 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4232 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4233 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4234 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4235 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4236 4237 # Checks for residue :70. 4238 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4239 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4240 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4241 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4242 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4243 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4244 4245 # Checks for residue :71. 4246 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4247 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4248 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4249 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4250 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4251 4252 # Test the conversion to k_AB from kex and pA. 4253 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4254 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4255 4256 # Test the conversion to k_BA from kex and pA. 4257 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4258 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4259 4260
4262 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4263 4264 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4265 """ 4266 4267 # Base data setup. 4268 self.setup_hansen_cpmg_data(model='CR72 full') 4269 4270 # Alias the spins. 4271 spin70 = return_spin(":70") 4272 spin71 = return_spin(":71") 4273 4274 # The R20 keys. 4275 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4276 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4277 4278 # Set the initial parameter values. 4279 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4280 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4281 spin70.pA = 0.9 4282 spin70.dw = 6.0 4283 spin70.kex = 1500.0 4284 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4285 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4286 spin71.pA = 0.9 4287 spin71.dw = 4.0 4288 spin71.kex = 1900.0 4289 4290 # Low precision optimisation. 4291 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4292 4293 # Printout. 4294 print("\n\nOptimised parameters:\n") 4295 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4296 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4297 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4298 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4299 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4300 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4301 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4302 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4303 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4304 4305 # Checks for residue :70. 4306 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4307 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4308 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4309 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4310 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4311 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4312 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4313 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4314 4315 # Checks for residue :71. 4316 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4317 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4318 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4319 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4320 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4321 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4322 4323 # Test the conversion to k_AB from kex and pA. 4324 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4325 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4326 4327 # Test the conversion to k_BA from kex and pA. 4328 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4329 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4330 4331
4333 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4334 4335 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4336 """ 4337 4338 # Base data setup. 4339 self.setup_hansen_cpmg_data(model='IT99') 4340 4341 # Alias the spins. 4342 spin70 = return_spin(":70") 4343 spin71 = return_spin(":71") 4344 4345 # The R20 keys. 4346 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4347 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4348 4349 # Set the initial parameter values. 4350 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4351 spin70.dw = 10.0 4352 spin70.pA = 0.5 4353 spin70.tex = 1000.09 4354 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4355 spin71.dw = 10.0 4356 spin71.pA = 0.95 4357 spin71.tex = 0.1 4358 4359 # Low precision optimisation. 4360 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4361 4362 # Printout. 4363 print("\n\nOptimised parameters:\n") 4364 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4365 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4366 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4367 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4368 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4369 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4370 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4371 4372 # Checks for residue :70. 4373 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4374 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4375 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4376 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4377 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4378 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4379 4380 # Checks for residue :71. 4381 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4382 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4383 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4384 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4385 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4386 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4387 4388
4390 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4391 4392 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4393 """ 4394 4395 # Base data setup. 4396 self.setup_hansen_cpmg_data(model='LM63') 4397 4398 # Alias the spins. 4399 spin70 = return_spin(":70") 4400 spin71 = return_spin(":71") 4401 4402 # The R20 keys. 4403 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4404 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4405 4406 # Set the initial parameter values. 4407 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4408 spin70.phi_ex = 0.3 4409 spin70.kex = 5000.0 4410 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4411 spin71.phi_ex = 0.1 4412 spin71.kex = 2500.0 4413 4414 # Low precision optimisation. 4415 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4416 4417 # Printout. 4418 print("\n\nOptimised parameters:\n") 4419 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4420 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4421 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4422 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4423 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4424 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4425 4426 # Checks for residue :70. 4427 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4428 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4429 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4430 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4431 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4432 4433 # Checks for residue :71. 4434 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4435 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4436 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4437 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4438 4439
4441 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4442 4443 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4444 """ 4445 4446 # Base data setup. 4447 self.setup_hansen_cpmg_data(model='LM63 3-site') 4448 4449 # Alias the spins. 4450 spin70 = return_spin(":70") 4451 spin71 = return_spin(":71") 4452 4453 # The R20 keys. 4454 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4455 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4456 4457 ## Set the initial parameter values. 4458 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4459 spin70.phi_ex_B = 0.14872003058250227 4460 spin70.phi_ex_C = 0.1319419923472704 4461 spin70.kB = 4103.672910444741 4462 spin70.kC = 7029.001690726248 4463 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4464 spin71.phi_ex_B = 0.04013553485505605 4465 spin71.phi_ex_C = 0.020050748406928887 4466 spin71.kB = 4045.3007136121364 4467 spin71.kC = 3586.38798270774 4468 4469 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4470 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4471 4472 # Low precision optimisation. 4473 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4474 4475 # Printout. 4476 print("\n\nOptimised parameters:\n") 4477 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4478 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4479 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4480 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4481 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4482 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4483 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4484 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4485 4486 # Checks for residue :70. 4487 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4488 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4489 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4490 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4491 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4492 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4493 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4494 4495 # Checks for residue :71. 4496 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4497 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4498 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4499 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4500 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4501 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4502 4503
4505 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4506 4507 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4508 """ 4509 4510 # Base data setup. 4511 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4512 4513 # Alias the spins. 4514 spin70 = return_spin(":70") 4515 spin71 = return_spin(":71") 4516 4517 # The R20 keys. 4518 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4519 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4520 4521 # Set the initial parameter values. 4522 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4523 spin70.pA = 0.9897754407 4524 spin70.dw = 5.642418428 4525 spin70.kex = 1743.666375 4526 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4527 spin71.pA = 0.9968032899 4528 spin71.dw = 4.577891393 4529 spin71.kex = 1830.044597 4530 4531 # Low precision optimisation. 4532 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4533 4534 # Printout. 4535 print("\n\nOptimised parameters:\n") 4536 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4537 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4538 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4539 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4540 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4541 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4542 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4543 4544 # Checks for residue :70. 4545 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4546 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4547 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4548 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4549 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4550 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4551 4552 # Checks for residue :71. 4553 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4554 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4555 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4556 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4557 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4558 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4559 4560 # Test the conversion to k_AB from kex and pA. 4561 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4562 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4563 4564 # Test the conversion to k_BA from kex and pA. 4565 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4566 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4567 4568
4570 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4571 4572 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4573 """ 4574 4575 # Base data setup. 4576 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4577 4578 # Alias the spins. 4579 spin70 = return_spin(":70") 4580 spin71 = return_spin(":71") 4581 4582 # The R20 keys. 4583 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4584 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4585 4586 # Set the initial parameter values. 4587 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4588 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4589 spin70.pA = 0.9884781357 4590 spin70.dw = 5.456507396 4591 spin70.kex = 1906.521189 4592 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4593 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4594 spin71.pA = 0.986709616684097 4595 spin71.dw = 2.09245158280905 4596 spin71.kex = 2438.2766211401 4597 4598 # Low precision optimisation. 4599 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4600 4601 # Printout. 4602 print("\n\nOptimised parameters:\n") 4603 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4604 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4605 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4606 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4607 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4608 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4609 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4610 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4611 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4612 4613 # Checks for residue :70. 4614 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4615 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4616 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4617 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4618 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4619 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4620 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4621 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4622 4623 # Checks for residue :71. 4624 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4625 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4626 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4627 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4628 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4629 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4630 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4631 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4632 4633 # Test the conversion to k_AB from kex and pA. 4634 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4635 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4636 4637 # Test the conversion to k_BA from kex and pA. 4638 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4639 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4640 4641
4643 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4644 4645 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4646 """ 4647 4648 # Base data setup. 4649 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4650 4651 # Alias the spins. 4652 spin70 = return_spin(":70") 4653 spin71 = return_spin(":71") 4654 4655 # The R20 keys. 4656 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4657 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4658 4659 # Set the initial parameter values. 4660 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4661 spin70.pA = 0.9 4662 spin70.dw = 6.0 4663 spin70.kex = 1500.0 4664 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4665 spin71.pA = 0.9 4666 spin71.dw = 4.0 4667 spin71.kex = 1900.0 4668 4669 # Low precision optimisation. 4670 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4671 4672 # Printout. 4673 print("\n\nOptimised parameters:\n") 4674 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4675 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4676 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4677 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4678 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4679 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4680 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4681 4682 # Checks for residue :70. 4683 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4684 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4685 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4686 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4687 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4688 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4689 4690 # Checks for residue :71. 4691 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4692 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4693 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4694 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4695 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4696 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4697 4698 # Test the conversion to k_AB from kex and pA. 4699 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4700 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4701 4702 # Test the conversion to k_BA from kex and pA. 4703 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4704 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4705 4706
4708 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4709 4710 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4711 """ 4712 4713 # Base data setup. 4714 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4715 4716 # Alias the spins. 4717 spin70 = return_spin(":70") 4718 spin71 = return_spin(":71") 4719 4720 # The R20 keys. 4721 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4722 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4723 4724 # Set the initial parameter values. 4725 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4726 spin70.pA = 0.9897519798 4727 spin70.dw = 5.644862195 4728 spin70.kex = 1723.820567 4729 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4730 spin71.pA = 0.9968032899 4731 spin71.dw = 4.577891393 4732 spin71.kex = 1830.044597 4733 4734 # Low precision optimisation. 4735 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4736 4737 # Printout. 4738 print("\n\nOptimised parameters:\n") 4739 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4740 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4741 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4742 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4743 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4744 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4745 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4746 4747 # Checks for residue :70. 4748 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4749 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4750 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4751 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4752 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4753 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4754 4755 # Checks for residue :71. 4756 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4757 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4758 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4759 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4760 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4761 4762 # Test the conversion to k_AB from kex and pA. 4763 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4764 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4765 4766 # Test the conversion to k_BA from kex and pA. 4767 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4768 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4769 4770
4772 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4773 4774 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4775 """ 4776 4777 # Base data setup. 4778 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4779 4780 # Alias the spins. 4781 spin70 = return_spin(":70") 4782 spin71 = return_spin(":71") 4783 4784 # The R20 keys. 4785 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4786 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4787 4788 # Set the initial parameter values. 4789 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4790 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4791 spin70.pA = 0.987648082613451 4792 spin70.dw = 5.30679853807572 4793 spin70.kex = 2033.25380420666 4794 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4795 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4796 spin71.pA = 0.992258541625787 4797 spin71.dw = 2.75140650899058 4798 spin71.kex = 2106.60885247431 4799 4800 # Low precision optimisation. 4801 self.interpreter.minimise.calculate() 4802 4803 # Checks for residue :70. 4804 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4805 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4806 4807
4808 - def test_hansen_cpmgfit_input(self):
4809 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4810 4811 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4812 """ 4813 4814 # Load the R2eff results file. 4815 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4816 self.interpreter.results.read(file_name) 4817 self.interpreter.deselect.spin(':4') 4818 4819 # Set up the model. 4820 self.interpreter.relax_disp.select_model('LM63') 4821 4822 # Generate the input files. 4823 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4824 4825 # What the files should contain. 4826 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4827 spin1 = [ 4828 "title :70@N\n", 4829 "fields 2 11.7432964915 18.7892743865\n", 4830 "function CPMG\n", 4831 "R2 1 10 20\n", 4832 "Rex 0 100.0 100\n", 4833 "Tau 0 10.0 100\n", 4834 "xmgr\n", 4835 "@ xaxis label \"1/tcp (1/ms)\"\n", 4836 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4837 "@ xaxis ticklabel format decimal\n", 4838 "@ yaxis ticklabel format decimal\n", 4839 "@ xaxis ticklabel char size 0.8\n", 4840 "@ yaxis ticklabel char size 0.8\n", 4841 "@ world xmin 0.0\n", 4842 "data\n", 4843 "0.133333 16.045541 0.310925 11.743296 \n", 4844 "0.266667 14.877925 0.303217 11.743296 \n", 4845 "0.400000 14.357820 0.299894 11.743296 \n", 4846 "0.533333 12.664495 0.289532 11.743296 \n", 4847 "0.666667 12.363205 0.287760 11.743296 \n", 4848 "0.800000 11.092532 0.280514 11.743296 \n", 4849 "0.933333 10.566090 0.277619 11.743296 \n", 4850 "1.066667 9.805807 0.273544 11.743296 \n", 4851 "1.200000 9.564301 0.272276 11.743296 \n", 4852 "1.333333 9.015634 0.269442 11.743296 \n", 4853 "1.466667 8.607765 0.267375 11.743296 \n", 4854 "1.600000 8.279997 0.265740 11.743296 \n", 4855 "1.733333 8.474536 0.266708 11.743296 \n", 4856 "1.866667 8.158973 0.265141 11.743296 \n", 4857 "2.000000 7.988631 0.264304 11.743296 \n", 4858 "0.133333 22.224914 0.166231 18.789274 \n", 4859 "0.266667 21.230874 0.162377 18.789274 \n", 4860 "0.400000 20.603704 0.160017 18.789274 \n", 4861 "0.533333 20.327797 0.158996 18.789274 \n", 4862 "0.666667 18.855377 0.153719 18.789274 \n", 4863 "0.800000 18.537531 0.152617 18.789274 \n", 4864 "0.933333 17.508069 0.149138 18.789274 \n", 4865 "1.066667 16.035604 0.144391 18.789274 \n", 4866 "1.200000 15.168192 0.141717 18.789274 \n", 4867 "1.333333 14.431802 0.139516 18.789274 \n", 4868 "1.466667 14.034137 0.138354 18.789274 \n", 4869 "1.600000 12.920148 0.135192 18.789274 \n", 4870 "1.733333 12.653673 0.134456 18.789274 \n", 4871 "1.866667 12.610864 0.134338 18.789274 \n", 4872 "2.000000 11.969303 0.132601 18.789274 \n" 4873 ] 4874 spin2 = [ 4875 "title :71@N\n", 4876 "fields 2 11.7432964915 18.7892743865\n", 4877 "function CPMG\n", 4878 "R2 1 10 20\n", 4879 "Rex 0 100.0 100\n", 4880 "Tau 0 10.0 100\n", 4881 "xmgr\n", 4882 "@ xaxis label \"1/tcp (1/ms)\"\n", 4883 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4884 "@ xaxis ticklabel format decimal\n", 4885 "@ yaxis ticklabel format decimal\n", 4886 "@ xaxis ticklabel char size 0.8\n", 4887 "@ yaxis ticklabel char size 0.8\n", 4888 "@ world xmin 0.0\n", 4889 "data\n", 4890 "0.133333 7.044342 0.170035 11.743296 \n", 4891 "0.266667 6.781033 0.169228 11.743296 \n", 4892 "0.400000 6.467623 0.168279 11.743296 \n", 4893 "0.533333 6.333340 0.167876 11.743296 \n", 4894 "0.666667 6.323238 0.167846 11.743296 \n", 4895 "0.800000 6.005245 0.166902 11.743296 \n", 4896 "0.933333 5.767052 0.166203 11.743296 \n", 4897 "1.066667 5.476968 0.165361 11.743296 \n", 4898 "1.200000 5.469949 0.165341 11.743296 \n", 4899 "1.333333 5.295113 0.164838 11.743296 \n", 4900 "1.466667 5.435648 0.165242 11.743296 \n", 4901 "1.600000 5.410400 0.165169 11.743296 \n", 4902 "1.733333 5.437554 0.165247 11.743296 \n", 4903 "1.866667 5.176844 0.164501 11.743296 \n", 4904 "2.000000 5.227232 0.164644 11.743296 \n", 4905 "0.133333 11.530903 0.081928 18.789274 \n", 4906 "0.266667 10.983094 0.081041 18.789274 \n", 4907 "0.400000 10.512403 0.080294 18.789274 \n", 4908 "0.533333 9.984805 0.079473 18.789274 \n", 4909 "0.666667 9.573163 0.078845 18.789274 \n", 4910 "0.800000 9.178810 0.078253 18.789274 \n", 4911 "0.933333 8.935719 0.077893 18.789274 \n", 4912 "1.066667 8.610147 0.077416 18.789274 \n", 4913 "1.200000 8.353778 0.077045 18.789274 \n", 4914 "1.333333 8.173729 0.076787 18.789274 \n", 4915 "1.466667 8.091607 0.076670 18.789274 \n", 4916 "1.600000 7.706420 0.076126 18.789274 \n", 4917 "1.733333 7.709125 0.076129 18.789274 \n", 4918 "1.866667 7.610856 0.075992 18.789274 \n", 4919 "2.000000 7.552584 0.075911 18.789274 \n", 4920 ] 4921 4922 # Check the batch file. 4923 print("\nChecking the batch file.") 4924 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 4925 lines = file.readlines() 4926 file.close() 4927 for i in range(len(lines)): 4928 self.assertEqual(batch_file[i], lines[i]) 4929 4930 # Check spin :70@N. 4931 print("\nChecking the spin :70@N input file.") 4932 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 4933 lines = file.readlines() 4934 file.close() 4935 for i in range(len(spin1)): 4936 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4937 for i in range(len(lines)): 4938 self.assertEqual(spin1[i], lines[i]) 4939 4940 # Check spin :71@N. 4941 print("\nChecking the spin :71@N input file.") 4942 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 4943 lines = file.readlines() 4944 file.close() 4945 for i in range(len(lines)): 4946 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4947 for i in range(len(spin2)): 4948 self.assertEqual(spin2[i], lines[i])
4949 4950
4952 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 4953 4954 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4955 4956 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 4957 4958 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 4959 - pA = 0.965402506690231, 4960 - dw = 0.805197170133360, 4961 - dwH = -0.595536627771890, 4962 - kex = 569.003663067619868, 4963 - chi2 = 9.297671357952812. 4964 """ 4965 4966 # Base data setup. 4967 self.setup_korzhnev_2005_data(data_list=['DQ']) 4968 4969 # Alias the spin. 4970 spin = return_spin(":9@N") 4971 4972 # The R20 keys. 4973 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 4974 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 4975 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 4976 4977 # Set the initial parameter values. 4978 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 4979 spin.pA = 0.965638501551899 4980 spin.dw = 2.8537583461577 4981 spin.dwH = -0.387633062766635 4982 spin.kex = 573.704033851592 4983 4984 # Low precision optimisation. 4985 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4986 4987 # Monte Carlo simulations. 4988 self.interpreter.monte_carlo.setup(number=2) 4989 self.interpreter.monte_carlo.create_data(method='back_calc') 4990 self.interpreter.monte_carlo.initial_values() 4991 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4992 self.interpreter.monte_carlo.error_analysis() 4993 4994 # Plot the dispersion curves. 4995 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4996 4997 # Save the results. 4998 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4999 5000 # Printout. 5001 print("\n\nOptimised parameters:\n") 5002 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5003 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5004 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5005 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5006 print("%-20s %20.15g" % ("pA", spin.pA)) 5007 print("%-20s %20.15g" % ("dw", spin.dw)) 5008 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5009 print("%-20s %20.15g" % ("kex", spin.kex)) 5010 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5011 5012 # Checks for residue :9. 5013 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5014 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5015 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5016 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5017 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5018 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5019 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5020 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5021 5022
5024 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5025 5026 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5027 5028 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5029 5030 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5031 - pA = 0.930027999814003, 5032 - dw = 4.338620619954370, 5033 - dwH = -0.274250775560818, 5034 - kex = 344.613362916544475, 5035 - chi2 = 10.367733168217050. 5036 """ 5037 5038 # Base data setup. 5039 self.setup_korzhnev_2005_data(data_list=['MQ']) 5040 5041 # Alias the spin. 5042 spin = return_spin(":9@N") 5043 5044 # The R20 keys. 5045 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5046 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5047 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5048 5049 # Set the initial parameter values. 5050 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5051 spin.pA = 0.930083249288083 5052 spin.dw = 4.33890689462363 5053 spin.dwH = -0.274316585638047 5054 spin.kex = 344.329651956132 5055 5056 # Low precision optimisation. 5057 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5058 5059 # Monte Carlo simulations. 5060 self.interpreter.monte_carlo.setup(number=2) 5061 self.interpreter.monte_carlo.create_data(method='back_calc') 5062 self.interpreter.monte_carlo.initial_values() 5063 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5064 self.interpreter.monte_carlo.error_analysis() 5065 5066 # Plot the dispersion curves. 5067 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5068 5069 # Save the results. 5070 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5071 5072 # Printout. 5073 print("\n\nOptimised parameters:\n") 5074 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5075 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5076 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5077 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5078 print("%-20s %20.15g" % ("pA", spin.pA)) 5079 print("%-20s %20.15g" % ("dw", spin.dw)) 5080 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5081 print("%-20s %20.15g" % ("kex", spin.kex)) 5082 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5083 5084 # Checks for residue :9. 5085 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5086 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5087 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5088 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5089 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5090 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5091 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5092 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5093 5094
5096 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5097 5098 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5099 5100 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5101 5102 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5103 - pA = 0.950003458294991, 5104 - dw = 4.358402855315123, 5105 - kex = 429.906473361926999, 5106 - chi2 = 17.393331915567252. 5107 """ 5108 5109 # Base data setup. 5110 self.setup_korzhnev_2005_data(data_list=['SQ']) 5111 5112 # Alias the spin. 5113 spin = return_spin(":9@N") 5114 5115 # The R20 keys. 5116 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5117 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5118 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5119 5120 # Set the initial parameter values. 5121 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5122 spin.pA = 0.950310172115387 5123 spin.dw = 4.356737157889636 5124 spin.kex = 433.176323890829849 5125 5126 # Low precision optimisation. 5127 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5128 5129 # Monte Carlo simulations. 5130 self.interpreter.monte_carlo.setup(number=2) 5131 self.interpreter.monte_carlo.create_data(method='back_calc') 5132 self.interpreter.monte_carlo.initial_values() 5133 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5134 self.interpreter.monte_carlo.error_analysis() 5135 5136 # Plot the dispersion curves. 5137 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5138 5139 # Save the results. 5140 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5141 5142 # Printout. 5143 print("\n\nOptimised parameters:\n") 5144 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5145 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5146 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5147 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5148 print("%-20s %20.15g" % ("pA", spin.pA)) 5149 print("%-20s %20.15g" % ("dw", spin.dw)) 5150 print("%-20s %20.15g" % ("kex", spin.kex)) 5151 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5152 5153 # Checks for residue :9. 5154 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5155 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5156 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5157 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5158 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5159 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5160 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5161 5162
5164 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5165 5166 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5167 5168 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5169 5170 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5171 - pA = 0.942452612380140, 5172 - dw = 0.858972784230892, 5173 - dwH = 0.087155962730608, 5174 - kex = 373.219151384798920, 5175 - chi2 = 23.863208106025152. 5176 """ 5177 5178 # Base data setup. 5179 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5180 5181 # Alias the spin. 5182 spin = return_spin(":9@N") 5183 5184 # The R20 keys. 5185 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5186 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5187 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5188 5189 # Set the initial parameter values. 5190 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5191 spin.pA = 0.942457332074014 5192 spin.dw = 0.850592422908884 5193 spin.dwH = 0.0881272284455416 5194 spin.kex = 372.745483351305 5195 5196 # Low precision optimisation. 5197 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5198 5199 # Monte Carlo simulations. 5200 self.interpreter.monte_carlo.setup(number=2) 5201 self.interpreter.monte_carlo.create_data(method='back_calc') 5202 self.interpreter.monte_carlo.initial_values() 5203 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5204 self.interpreter.monte_carlo.error_analysis() 5205 5206 # Plot the dispersion curves. 5207 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5208 5209 # Save the results. 5210 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5211 5212 # Printout. 5213 print("\n\nOptimised parameters:\n") 5214 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5215 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5216 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5217 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5218 print("%-20s %20.15g" % ("pA", spin.pA)) 5219 print("%-20s %20.15g" % ("dw", spin.dw)) 5220 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5221 print("%-20s %20.15g" % ("kex", spin.kex)) 5222 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5223 5224 # Checks for residue :9. 5225 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5226 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5227 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5228 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5229 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5230 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5231 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5232 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5233 5234
5236 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5237 5238 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5239 5240 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5241 5242 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5243 - pA = 0.936911090448340, 5244 - dw = 4.325314846914845, 5245 - dwH = -0.213870168665628, 5246 - kex = 487.361914835074117, 5247 - chi2 = 14.870371897291138. 5248 """ 5249 5250 # Base data setup. 5251 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5252 5253 # Alias the spin. 5254 spin = return_spin(":9@N") 5255 5256 # The R20 keys. 5257 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5258 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5259 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5260 5261 # Set the initial parameter values. 5262 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5263 spin.pA = 0.936884348941701 5264 spin.dw = 4.326454531583964 5265 spin.dwH = -0.214026093221782 5266 spin.kex = 487.043592705469223 5267 5268 # Low precision optimisation. 5269 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5270 5271 # Monte Carlo simulations. 5272 self.interpreter.monte_carlo.setup(number=2) 5273 self.interpreter.monte_carlo.create_data(method='back_calc') 5274 self.interpreter.monte_carlo.initial_values() 5275 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5276 self.interpreter.monte_carlo.error_analysis() 5277 5278 # Plot the dispersion curves. 5279 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5280 5281 # Save the results. 5282 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5283 5284 # Printout. 5285 print("\n\nOptimised parameters:\n") 5286 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5287 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5288 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5289 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5290 print("%-20s %20.15g" % ("pA", spin.pA)) 5291 print("%-20s %20.15g" % ("dw", spin.dw)) 5292 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5293 print("%-20s %20.15g" % ("kex", spin.kex)) 5294 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5295 5296 # Checks for residue :9. 5297 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5298 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5299 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5300 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5301 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5302 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5303 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5304 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5305 5306
5308 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5309 5310 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5311 5312 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5313 5314 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5315 - pA = 0.946949480545876, 5316 - dwH = -0.265279672133308, 5317 - kex = 406.548178869750700, 5318 - chi2 = 50.400680290545026. 5319 """ 5320 5321 # Base data setup. 5322 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5323 5324 # Alias the spin. 5325 spin = return_spin(":9@N") 5326 5327 # The R20 keys. 5328 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5329 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5330 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5331 5332 # Set the initial parameter values. 5333 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5334 spin.pA = 0.946990967372467 5335 spin.dwH = -0.265308128403529 5336 spin.kex = 406.843250675648 5337 5338 # Low precision optimisation. 5339 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5340 5341 # Monte Carlo simulations. 5342 self.interpreter.monte_carlo.setup(number=2) 5343 self.interpreter.monte_carlo.create_data(method='back_calc') 5344 self.interpreter.monte_carlo.initial_values() 5345 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5346 self.interpreter.monte_carlo.error_analysis() 5347 5348 # Plot the dispersion curves. 5349 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5350 5351 # Save the results. 5352 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5353 5354 # Printout. 5355 print("\n\nOptimised parameters:\n") 5356 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5357 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5358 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5359 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5360 print("%-20s %20.15g" % ("pA", spin.pA)) 5361 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5362 print("%-20s %20.15g" % ("kex", spin.kex)) 5363 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5364 5365 # Checks for residue :9. 5366 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5367 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5368 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5369 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5370 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5371 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5372 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5373 5374
5376 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5377 5378 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5379 5380 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5381 5382 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5383 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5384 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5385 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5386 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5387 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5388 - pA = 0.943125351763911, 5389 - dw = 4.421827493809807, 5390 - dwH = -0.272637034755752, 5391 - kex = 360.609744568697238, 5392 - chi2 = 162.589570340050813. 5393 """ 5394 5395 # Base data setup. 5396 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5397 5398 # Alias the spin. 5399 spin = return_spin(":9@N") 5400 5401 # The R20 keys. 5402 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5403 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5404 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5405 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5406 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5407 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5408 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5409 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5410 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5411 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5412 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5413 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5414 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5415 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5416 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5417 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5418 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5419 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5420 5421 # Set the initial parameter values. 5422 spin.r2 = { 5423 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5424 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5425 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5426 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5427 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5428 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5429 } 5430 spin.pA = 0.943129019477673 5431 spin.dw = 4.42209952545181 5432 spin.dwH = -0.27258970590969 5433 spin.kex = 360.516132791038 5434 5435 # Low precision optimisation. 5436 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5437 5438 # Monte Carlo simulations. 5439 self.interpreter.monte_carlo.setup(number=2) 5440 self.interpreter.monte_carlo.create_data(method='back_calc') 5441 self.interpreter.monte_carlo.initial_values() 5442 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5443 self.interpreter.monte_carlo.error_analysis() 5444 5445 # Plot the dispersion curves. 5446 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5447 5448 # Save the results. 5449 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5450 5451 # Printout. 5452 print("\n\nOptimised parameters:\n") 5453 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5454 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5455 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5456 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5457 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5458 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5459 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5460 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5461 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5462 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5463 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5464 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5465 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5466 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5467 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5468 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5469 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5470 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5471 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5472 print("%-20s %20.15g" % ("pA", spin.pA)) 5473 print("%-20s %20.15g" % ("dw", spin.dw)) 5474 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5475 print("%-20s %20.15g" % ("kex", spin.kex)) 5476 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5477 5478 # Checks for residue :9. 5479 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5480 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5481 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5482 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5483 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5484 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5485 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5486 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5487 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5488 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5489 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5490 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5491 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5492 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5493 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5494 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5495 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5496 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5497 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5498 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5499 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5500 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5501 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5502 5503
5505 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5506 5507 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5508 5509 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5510 5511 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5512 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5513 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5514 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5515 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5516 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5517 - pA = 0.943125351763911, 5518 - dw = 4.421827493809807, 5519 - dwH = -0.272637034755752, 5520 - kex = 360.609744568697238, 5521 - chi2 = 162.589570340050813. 5522 """ 5523 5524 # Base data setup. 5525 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5526 5527 # Alias the spin. 5528 spin = return_spin(":9@N") 5529 5530 # The R20 keys. 5531 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5532 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5533 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5534 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5535 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5536 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5537 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5538 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5539 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5540 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5541 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5542 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5543 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5544 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5545 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5546 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5547 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5548 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5549 5550 # Set the initial parameter values. 5551 spin.r2 = { 5552 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5553 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5554 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5555 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5556 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5557 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5558 } 5559 spin.pA = 0.943129019477673 5560 spin.dw = 4.42209952545181 5561 spin.dwH = -0.27258970590969 5562 spin.kex = 360.516132791038 5563 5564 # Calc the chi2 values at these parameters. 5565 self.interpreter.minimise.calculate(verbosity=1) 5566 5567 # Printout. 5568 print("\n\nOptimised parameters:\n") 5569 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5570 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5571 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5572 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5573 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5574 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5575 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5576 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5577 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5578 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5579 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5580 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5581 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5582 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5583 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5584 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5585 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5586 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5587 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5588 print("%-20s %20.15g" % ("pA", spin.pA)) 5589 print("%-20s %20.15g" % ("dw", spin.dw)) 5590 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5591 print("%-20s %20.15g" % ("kex", spin.kex)) 5592 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5593 5594 # Checks for residue :9. 5595 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5596 5597
5599 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5600 5601 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5602 5603 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5604 5605 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5606 - 0.483 0.89623903 2.4503699912708878 5607 - 0.545 1.1694838 5608 - 0.545 1.1761503 5609 - 0.622 1.294 5610 - 0.669 1.5176493 5611 - 0.722 1.6238791 5612 - 0.813 1.9395758 5613 - 1.011 2.3558415 10.547000429321157 5614 """ 5615 5616 # Base data setup. 5617 model = 'TSMFK01' 5618 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5619 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5620 5621 # Alias the spins. 5622 res61L = cdp.mol[0].res[0].spin[0] 5623 5624 # The R20 keys. 5625 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5626 5627 # Set the initial parameter values. 5628 res61L.r2a = {r20_key1: 8.0} 5629 res61L.dw = 6.5 5630 res61L.k_AB = 2.5 5631 5632 # Low precision optimisation. 5633 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5634 5635 # Start testing all possible combinations of graphs. 5636 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5637 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5638 interpolate_types = [INTERPOLATE_DISP] 5639 5640 # Write to temp folder. 5641 result_dir_name = ds.tmpdir 5642 result_folders = [model] 5643 spin_id = ":61@N" 5644 5645 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5646 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5647 5648 for result_folder in result_folders: 5649 for y_axis in y_axis_types: 5650 for x_axis in x_axis_types: 5651 for interpolate in interpolate_types: 5652 # Determine file name: 5653 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5654 5655 # Make the file name. 5656 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5657 5658 # Write the curves. 5659 dir = result_dir_name+sep+result_folder 5660 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5661 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5662 5663 # Get the file path. 5664 file_path = get_file_path(file_name, dir) 5665 5666 # Test the plot file exists. 5667 print("Testing file access to graph: %s"%file_path) 5668 self.assert_(access(file_path, F_OK)) 5669 5670 # Now open, and compare content, line by line. 5671 file_prod = open(file_path) 5672 lines_prod = file_prod.readlines() 5673 file_prod.close() 5674 5675 # Define file to compare against. 5676 dir_comp = data_path+sep+result_folder 5677 file_path_comp = get_file_path(file_name, dir_comp) 5678 file_comp = open(file_path_comp) 5679 lines_comp = file_comp.readlines() 5680 file_comp.close() 5681 5682 ## Assert number of lines is equal. 5683 self.assertEqual(len(lines_prod), len(lines_comp)) 5684 for j in range(len(lines_prod)): 5685 # Make the string test 5686 first_char = lines_prod[j][0] 5687 if first_char in ["@", "&"]: 5688 self.assertEqual(lines_prod[j], lines_comp[j]) 5689 else: 5690 # Split string in x, y, error. 5691 # The error would change per run. 5692 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5693 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5694 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5695 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5696 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5697 5698
5700 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5701 5702 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5703 """ 5704 5705 # Base data setup. 5706 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5707 5708 # Alias the spins. 5709 res61L = cdp.mol[0].res[0].spin[0] 5710 5711 # The R20 keys. 5712 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5713 5714 # Set the initial parameter values. 5715 res61L.r2 = {r20_key1: 8.0} 5716 res61L.pA = 0.9 5717 res61L.dw = 6.0 5718 res61L.kex = 600.0 5719 5720 # Low precision optimisation. 5721 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5722 5723 # Printout. 5724 print("\n\nOptimised parameters:\n") 5725 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5726 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5727 print("%-20s %20.15g" % ("pA", res61L.pA)) 5728 print("%-20s %20.15g" % ("dw", res61L.dw)) 5729 print("%-20s %20.15g" % ("kex", res61L.kex)) 5730 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5731 5732 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5733 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5734 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5735 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5736 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5737 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5738 5739 # Test the conversion to k_AB from kex and pA. 5740 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5741 5742 # Test the conversion to k_BA from kex and pA. 5743 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5744 5745
5747 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5748 5749 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5750 """ 5751 5752 # Base data setup. 5753 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5754 5755 # Alias the spins. 5756 res61L = cdp.mol[0].res[0].spin[0] 5757 5758 # The R20 keys. 5759 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5760 5761 # Set the initial parameter values. 5762 res61L.r2a = {r20_key1: 8.0} 5763 res61L.r2b = {r20_key1: 105.0} 5764 res61L.pA = 0.9 5765 res61L.dw = 6.0 5766 res61L.kex = 500.0 5767 5768 # Low precision optimisation. 5769 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5770 5771 # Printout. 5772 print("\n\nOptimised parameters:\n") 5773 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5774 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5775 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5776 print("%-20s %20.15g" % ("pA", res61L.pA)) 5777 print("%-20s %20.15g" % ("dw", res61L.dw)) 5778 print("%-20s %20.15g" % ("kex", res61L.kex)) 5779 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5780 5781 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5782 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5783 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5784 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5785 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5786 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5787 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5788 5789
5791 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5792 5793 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5794 5795 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5796 5797 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5798 - 0.483 0.89623903 2.4503699912708878 5799 - 0.545 1.1694838 5800 - 0.545 1.1761503 5801 - 0.622 1.294 5802 - 0.669 1.5176493 5803 - 0.722 1.6238791 5804 - 0.813 1.9395758 5805 - 1.011 2.3558415 10.547000429321157 5806 """ 5807 5808 # Base data setup. 5809 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5810 5811 # Alias the spins. 5812 res61L = cdp.mol[0].res[0].spin[0] 5813 5814 # The R20 keys. 5815 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5816 5817 # Set the initial parameter values. 5818 res61L.r2a = {r20_key1: 8.0} 5819 res61L.dw = 6.5 5820 res61L.k_AB = 2.5 5821 5822 # Low precision optimisation. 5823 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5824 5825 # Printout. 5826 print("\n\nOptimised parameters:\n") 5827 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5828 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5829 print("%-20s %20.15g" % ("dw", res61L.dw)) 5830 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5831 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5832 5833 # Checks for residue :61. Reference values from paper 5834 5835 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5836 5837
5839 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5840 5841 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5842 5843 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5844 5845 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5846 5847 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5848 - k_AB = 11.3 +/- 0.7 s^-1, 5849 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5850 - R2 = 8.0 +/- 0.5 s^-1. 5851 5852 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5853 - k_AB = 10.55 +/- 0.08 s^-1, 5854 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5855 - R2 = 8.4 +/- 0.3 s^-1. 5856 5857 Conversion of paper results to relax results is performed by: 5858 5859 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5860 5861 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5862 5863 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5864 - 0.483 0.89623903 2.4503699912708878 5865 - 0.545 1.1694838 5866 - 0.545 1.1761503 5867 - 0.622 1.294 5868 - 0.669 1.5176493 5869 - 0.722 1.6238791 5870 - 0.813 1.9395758 5871 - 1.011 2.3558415 10.547000429321157 5872 """ 5873 5874 # Base data setup. 5875 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5876 5877 # Alias the spins. 5878 res61L = cdp.mol[0].res[0].spin[0] 5879 5880 # The R20 keys. 5881 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5882 5883 # Set the initial parameter values. 5884 res61L.r2a = {r20_key1: 8.0} 5885 res61L.dw = 6.5 5886 res61L.k_AB = 11.0 5887 5888 # Low precision optimisation. 5889 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5890 5891 # Printout. 5892 print("\n\nOptimised parameters:\n") 5893 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5894 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5895 print("%-20s %20.15g" % ("dw", res61L.dw)) 5896 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5897 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5898 5899 # Checks for residue :61. Reference values from paper 5900 5901 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 5902 self.assertAlmostEqual(res61L.dw, 6.41, 0) 5903 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5904 5905
5906 - def test_lm63_3site_synthetic(self):
5907 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 5908 5909 # The path to the data files. 5910 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 5911 5912 # Load the state file. 5913 self.interpreter.reset() 5914 self.interpreter.state.load(data_path+sep+'r2eff_values') 5915 5916 # A new data pipe. 5917 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 5918 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 5919 5920 # Set up the model data. 5921 self.interpreter.relax_disp.select_model(model='LM63 3-site') 5922 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 5923 self.interpreter.spin.isotope('15N') 5924 5925 # Alias the spins. 5926 spin1 = return_spin(":1") 5927 spin2 = return_spin(":2") 5928 5929 # The R20 keys. 5930 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5931 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5932 5933 # Manually set the parameter values. 5934 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 5935 spin1.phi_ex_B = 0.1 5936 spin1.phi_ex_C = 0.5 5937 spin1.kB = 1500.0 5938 spin1.kC = 2500.0 5939 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 5940 spin2.phi_ex_B = 0.1 5941 spin2.phi_ex_C = 0.5 5942 spin2.kB = 1500.0 5943 spin2.kC = 2500.0 5944 5945 # Low precision optimisation. 5946 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5947 5948 # Monte Carlo simulations. 5949 self.interpreter.monte_carlo.setup(number=3) 5950 self.interpreter.monte_carlo.create_data(method='back_calc') 5951 self.interpreter.monte_carlo.initial_values() 5952 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 5953 self.interpreter.monte_carlo.error_analysis() 5954 5955 # Save the results. 5956 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 5957 5958 # The model checks. 5959 print("\n\nOptimised parameters:\n") 5960 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 5961 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 5962 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 5963 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 5964 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 5965 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 5966 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 5967 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 5968 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 5969 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 5970 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5971 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5972 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5973 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5974 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 5975 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 5976 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 5977 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5978 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5979 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5980 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5981 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
5982 5983
5984 - def test_m61_data_to_m61(self):
5985 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 5986 5987 # Fixed time variable. 5988 ds.fixed = True 5989 5990 # Execute the script. 5991 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 5992 5993 # The original parameters. 5994 i0 = [100000.0, 20000.0] 5995 r1rho_prime = [2.25, 24.0] 5996 pA = 0.7 5997 kex = 1000.0 5998 delta_omega = [1.0, 2.0] 5999 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6000 phi_ex = [] 6001 for i in range(2): 6002 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6003 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6004 6005 # Switch to the 'R2eff' model data pipe, then check for each spin. 6006 self.interpreter.pipe.switch('R2eff - relax_disp') 6007 spin_index = 0 6008 for spin, spin_id in spin_loop(return_id=True): 6009 # Printout. 6010 print("\nSpin %s." % spin_id) 6011 6012 # Check the fitted parameters. 6013 for i in range(len(keys)): 6014 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6015 6016 # Increment the spin index. 6017 spin_index += 1 6018 6019 # The R20 keys. 6020 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6021 6022 # Switch to the 'M61' model data pipe, then check for each spin. 6023 self.interpreter.pipe.switch('M61 - relax_disp') 6024 spin_index = 0 6025 for spin, spin_id in spin_loop(return_id=True): 6026 # Printout. 6027 print("\nSpin %s." % spin_id) 6028 6029 # Check the fitted parameters. 6030 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6031 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6032 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6033 6034 # Increment the spin index. 6035 spin_index += 1
6036 6037
6038 - def test_m61_exp_data_to_m61(self):
6039 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6040 6041 # Fixed time variable. 6042 ds.fixed = False 6043 6044 # Single spin optimisation. 6045 ds.single = True 6046 6047 # Execute the script. 6048 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6049 6050 # The original parameters. 6051 i0 = [100000.0, 20000.0] 6052 r1rho_prime = [2.25, 24.0] 6053 pA = 0.7 6054 kex = 1000.0 6055 delta_omega = [1.0, 2.0] 6056 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6057 phi_ex = [] 6058 for i in range(2): 6059 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6060 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6061 6062 # Switch to the 'R2eff' model data pipe, then check for each spin. 6063 self.interpreter.pipe.switch('R2eff - relax_disp') 6064 spin_index = 0 6065 for spin, spin_id in spin_loop(return_id=True): 6066 # Printout. 6067 print("\nSpin %s." % spin_id) 6068 6069 # Check the fitted parameters. 6070 for i in range(len(keys)): 6071 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6072 6073 # Increment the spin index. 6074 spin_index += 1 6075 6076 # The R20 keys. 6077 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6078 6079 # Switch to the 'M61' model data pipe, then check for each spin. 6080 self.interpreter.pipe.switch('M61 - relax_disp') 6081 spin_index = 0 6082 for spin, spin_id in spin_loop(return_id=True): 6083 # Printout. 6084 print("\nSpin %s." % spin_id) 6085 6086 # Check the fitted parameters. 6087 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6088 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6089 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6090 6091 # Increment the spin index. 6092 spin_index += 1
6093 6094
6095 - def test_m61b_data_to_m61b(self):
6096 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6097 6098 # Execute the script. 6099 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6100 6101 # The original parameters. 6102 i0 = [100000.0, 20000.0] 6103 r1rho_prime = [10.0, 24.0] 6104 pA = 0.95 6105 kex = 2000.0 6106 delta_omega = [1.0, 2.0] 6107 6108 # The R20 keys. 6109 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6110 6111 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6112 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6113 spin_index = 0 6114 for spin, spin_id in spin_loop(return_id=True): 6115 # Printout. 6116 print("\nSpin %s." % spin_id) 6117 6118 # Check the fitted parameters. 6119 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6120 self.assertAlmostEqual(spin.pA, pA, 2) 6121 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6122 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6123 6124 # Increment the spin index. 6125 spin_index += 1
6126 6127
6129 """Test that all models which can nest, have all their parameters converted.""" 6130 6131 # Set the experiment type. 6132 cdp.exp_type_list = EXP_TYPE_LIST 6133 6134 # Get info for all models. 6135 all_models_info = models_info(models=MODEL_LIST_FULL) 6136 6137 # Loop over all models. 6138 print("Printing the listed of nested models for each model.") 6139 print("#########################################") 6140 for model_info in all_models_info: 6141 print("%s"%model_info.model), 6142 print("<-"), 6143 nest_list = model_info.nest_list 6144 if nest_list == None: 6145 nest_list = ["None"] 6146 print(', '.join(map(str, nest_list))) 6147 6148 # Skip if there is no model to nest from. 6149 if nest_list == ["None"]: 6150 continue 6151 6152 # Assign params to variable. 6153 model_params = model_info.params 6154 6155 # Now loop over the nested models. 6156 for nested_model in nest_list: 6157 # Get the params for the nested model. 6158 nested_model_params = MODEL_PARAMS[nested_model] 6159 6160 # Get the dictionary of parameter conversion. 6161 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6162 6163 # Test the number of elements in the dictionary. 6164 self.assertEqual(len(par_dic), len(model_params)) 6165 6166 # Loop over dictionary. 6167 for param in par_dic: 6168 if param != par_dic[param]: 6169 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6170 self.assertNotEqual(par_dic[param], None)
6171 6172
6173 - def test_ns_mmq_3site(self):
6174 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6175 6176 # Execute the script. 6177 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6178 6179 # Check the chi-squared value. 6180 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6181 6182
6183 - def test_ns_mmq_3site_linear(self):
6184 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6185 6186 # Execute the script. 6187 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6188 6189 # Check the chi-squared value. 6190 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6191 6192
6193 - def test_ns_r1rho_3site(self):
6194 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6195 6196 # Execute the script. 6197 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6198 6199 # Check the chi-squared value. 6200 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6201 6202
6203 - def test_ns_r1rho_3site_linear(self):
6204 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6205 6206 # Execute the script. 6207 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6208 6209 # Check the chi-squared value. 6210 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6211 6212
6213 - def test_repeat_cpmg(self):
6214 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6215 6216 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6217 """ 6218 6219 # Reset. 6220 self.interpreter.reset() 6221 6222 # Define base path to files. 6223 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6224 6225 # Setup dictionary with settings. 6226 sdic = {} 6227 6228 # Spectrometer frqs in list. 6229 sfrq_1 = 499.86214 6230 sfrq_2 = 599.8908587 6231 sfrqs = [sfrq_1, sfrq_2] 6232 6233 # Store in dictionary. 6234 sdic['sfrqs'] = sfrqs 6235 6236 # Store unit for frq. 6237 sdic['sfrq_unit'] = 'MHz' 6238 6239 # Store exp_type 6240 sdic['exp_type'] = 'SQ CPMG' 6241 6242 # Store spin isotope 6243 sdic['isotope'] = '15N' 6244 6245 # How intensity was measured. 6246 sdic['int_method'] = 'height' 6247 6248 # Define the time for result directory. 6249 sdic['time'] = '2014_09' 6250 6251 # Initialize frq dics. 6252 for frq in sfrqs: 6253 key = DIC_KEY_FORMAT % (frq) 6254 sdic[key] = {} 6255 6256 # Set keys. 6257 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6258 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6259 6260 # Store time T2. 6261 sdic[e_1]['time_T2'] = 0.04 6262 sdic[e_2]['time_T2'] = 0.06 6263 6264 # Set ncyc. 6265 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6266 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6267 6268 # Calculate the cpmg_frq and store. 6269 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6270 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6271 6272 # Define peak lists. 6273 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6274 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6275 sdic[e_1]['peaks_folder'] = peaks_folder_1 6276 sdic[e_2]['peaks_folder'] = peaks_folder_2 6277 6278 # Define folder to all rmsd files. 6279 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6280 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6281 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6282 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6283 6284 # Define temporary folder. 6285 sdic['results_dir'] = self.tmpdir 6286 6287 # Setup class with data. 6288 RDR = Relax_disp_rep(sdic) 6289 6290 # Setup base information. 6291 RDR.set_base_cpmg(method='FT', glob_ini=128) 6292 6293 methods = ['FT', 'MDD'] 6294 #methods = ['FT'] 6295 6296 # Set the intensity. 6297 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6298 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6299 6300 # Try plot some intensity correlations. 6301 if True: 6302 selection = None 6303 6304 # Now make a spin selection. 6305 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6306 6307 # For mdd 6308 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6309 6310 # Plot correlation of intensity 6311 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6312 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6313 corr_data = [fig1, fig2] 6314 6315 write_stats = True 6316 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6317 6318 # Open stat file. 6319 if write_stats: 6320 for i, corr_data_i in enumerate(corr_data): 6321 data, methods, glob_inis = corr_data[i] 6322 data_x, data_y = data 6323 method_x, method_y = methods 6324 glob_ini_x, glob_ini_y = glob_inis 6325 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6326 np = len(x) 6327 6328 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6329 6330 if selection == None: 6331 file_name = file_name_ini + '_all.txt' 6332 else: 6333 file_name = file_name_ini + '_sel.txt' 6334 path = RDR.results_dir 6335 data = extract_data(file=file_name, dir=path) 6336 6337 # Loop over the lines. 6338 for i, data_i in enumerate(data): 6339 print(i, data_i) 6340 6341 6342 # Try plot some intensity statistics. 6343 if True: 6344 # Collect r2eff values. 6345 selections = [None, ':2,3'] 6346 for selection in selections: 6347 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6348 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6349 6350 # Get R2eff stats. 6351 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6352 6353 ## Plot R2eff stats 6354 write_stats = True 6355 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6356 6357 # Open stat file. 6358 if write_stats: 6359 if selection == None: 6360 file_name = 'int_stat_all.txt' 6361 else: 6362 file_name = 'int_stat_sel.txt' 6363 path = RDR.results_dir 6364 data = extract_data(file=file_name, dir=path) 6365 6366 # Loop over the lines. 6367 for i, data_i in enumerate(data): 6368 print(i, data_i) 6369 6370 6371 # Try write some R2eff correlations. 6372 if True: 6373 selection = None 6374 # Collect r2eff values. 6375 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6376 6377 # For all spins, mdd 6378 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6379 6380 # Plot correlation of intensity 6381 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6382 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6383 corr_data = [fig1, fig2] 6384 6385 write_stats = True 6386 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6387 6388 # Open stat file. 6389 if write_stats: 6390 for i, corr_data_i in enumerate(corr_data): 6391 data, methods, glob_inis = corr_data[i] 6392 data_x, data_y = data 6393 method_x, method_y = methods 6394 glob_ini_x, glob_ini_y = glob_inis 6395 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6396 np = len(x) 6397 6398 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6399 6400 if selection == None: 6401 file_name = file_name_ini + '_all.txt' 6402 else: 6403 file_name = file_name_ini + '_sel.txt' 6404 path = RDR.results_dir 6405 data = extract_data(file=file_name, dir=path) 6406 6407 # Loop over the lines. 6408 for i, data_i in enumerate(data): 6409 print(i, data_i) 6410 6411 6412 # Try plot some R2eff statistics. 6413 if True: 6414 # Collect r2eff values. 6415 selections = [None, ':2,3'] 6416 for selection in selections: 6417 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6418 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6419 6420 # Get R2eff stats. 6421 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6422 6423 ## Plot R2eff stats 6424 write_stats = True 6425 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6426 6427 # Open stat file. 6428 if write_stats: 6429 if selection == None: 6430 file_name = 'r2eff_stat_all.txt' 6431 else: 6432 file_name = 'r2eff_stat_sel.txt' 6433 path = RDR.results_dir 6434 data = extract_data(file=file_name, dir=path) 6435 6436 # Loop over the lines. 6437 for i, data_i in enumerate(data): 6438 print(i, data_i) 6439 6440 6441 # Do minimisation individual. 6442 if True: 6443 methods = ['FT', 'MDD'] 6444 # Now calculate R2eff. 6445 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6446 6447 min_methods = [['FT'], ['MDD']] 6448 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6449 6450 #min_methods = [['FT']] 6451 #min_list_glob_ini = [[128]] 6452 #selection = ':2,3' 6453 selection = None 6454 6455 for i, methods in enumerate(min_methods): 6456 list_glob_ini = min_list_glob_ini[i] 6457 6458 if True: 6459 # First get data. 6460 if True: 6461 # First load all data. 6462 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6463 6464 # Then set R20 6465 if True: 6466 # Set R20 from min R2eff in preparation for Grid search. 6467 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6468 6469 # Check and print parameters. 6470 if True: 6471 # Print for pipe name 6472 method = methods[0] 6473 glob_ini = list_glob_ini[0] 6474 6475 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6476 RDR.spin_display_params(pipe_name=test_pipe_name) 6477 6478 # Then Grid search. 6479 if True: 6480 # Do Grid search. 6481 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6482 6483 # Then Minimise. 6484 if True: 6485 # Minimise 6486 RDR.opt_max_iterations = int(1e2) 6487 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6488 6489 #print asd 6490 6491 # Plot statistics. 6492 # Try plot some minimisation correlations. 6493 if True: 6494 selections = [None, ':2,3'] 6495 for selection in selections: 6496 # Collect param values. 6497 analysis = 'min_ind' 6498 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6499 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6500 6501 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6502 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6503 corr_data = [fig1, fig2] 6504 6505 write_stats = True 6506 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6507 6508 # Open stat file. 6509 if write_stats: 6510 for i, corr_data_i in enumerate(corr_data): 6511 data, methods, glob_inis = corr_data[i] 6512 data_x, data_y = data 6513 method_x, method_y = methods 6514 glob_ini_x, glob_ini_y = glob_inis 6515 6516 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6517 6518 if selection == None: 6519 file_name = file_name_ini + '_all.txt' 6520 else: 6521 file_name = file_name_ini + '_sel.txt' 6522 path = RDR.results_dir 6523 data = extract_data(file=file_name, dir=path) 6524 6525 # Loop over the lines. 6526 for i, data_i in enumerate(data): 6527 print(i, data_i) 6528 6529 # Try plot some minimisation statistics. 6530 if True: 6531 # Collect param values. 6532 #selections = [None, ':2,3'] 6533 selections = [None, ':2,3'] 6534 for selection in selections: 6535 analysis = 'min_ind' 6536 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6537 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6538 6539 # Get param stats. 6540 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6541 6542 ## Plot R2eff stats 6543 write_stats = True 6544 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6545 6546 # Open stat file. 6547 if write_stats: 6548 if selection == None: 6549 file_name = '%s_stat_all.txt' % (analysis) 6550 else: 6551 file_name = '%s_stat_sel.txt' % (analysis) 6552 path = RDR.results_dir 6553 data = extract_data(file=file_name, dir=path) 6554 6555 # Loop over the lines. 6556 for i, data_i in enumerate(data): 6557 print(i, data_i) 6558 6559 6560 # Do minimisation clustered. 6561 if True: 6562 methods = ['FT', 'MDD'] 6563 # Now calculate R2eff. 6564 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6565 6566 min_methods = [['FT'], ['MDD']] 6567 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6568 6569 #min_methods = [['FT']] 6570 #min_list_glob_ini = [[128]] 6571 selection = ':2,3' 6572 6573 for i, methods in enumerate(min_methods): 6574 list_glob_ini = min_list_glob_ini[i] 6575 6576 if True: 6577 # First get data. 6578 if True: 6579 # First load all data. 6580 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6581 6582 # Then select spins. 6583 if True: 6584 # Deselect all spins. 6585 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6586 6587 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6588 6589 # Then preset values. 6590 if True: 6591 # Set k_AB for Grid search. 6592 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6593 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6594 6595 # Then set R20 6596 if True: 6597 # Set R20 from min R2eff in preparation for Grid search. 6598 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6599 6600 # Check and print parameters. 6601 if True: 6602 # Print for pipe name 6603 method = methods[0] 6604 glob_ini = list_glob_ini[0] 6605 6606 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6607 RDR.spin_display_params(pipe_name=test_pipe_name) 6608 6609 # Then Grid search. 6610 if True: 6611 # Do Grid search. 6612 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6613 6614 # Then cluster spins. 6615 if True: 6616 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6617 6618 # Then Minimise. 6619 if True: 6620 # Minimise 6621 RDR.opt_max_iterations = int(1e2) 6622 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6623 6624 # Plot statistics. 6625 # Try plot some minimisation correlations. 6626 if True: 6627 selection = ':2,3' 6628 # Collect param values. 6629 analysis = 'min' 6630 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6631 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6632 6633 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6634 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6635 corr_data = [fig1, fig2] 6636 6637 write_stats = True 6638 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6639 6640 # Open stat file. 6641 if write_stats: 6642 for i, corr_data_i in enumerate(corr_data): 6643 data, methods, glob_inis = corr_data[i] 6644 data_x, data_y = data 6645 method_x, method_y = methods 6646 glob_ini_x, glob_ini_y = glob_inis 6647 6648 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6649 6650 if selection == None: 6651 file_name = file_name_ini + '_all.txt' 6652 else: 6653 file_name = file_name_ini + '_sel.txt' 6654 path = RDR.results_dir 6655 data = extract_data(file=file_name, dir=path) 6656 6657 # Loop over the lines. 6658 for i, data_i in enumerate(data): 6659 print(i, data_i) 6660 6661 # Try plot some minimisation statistics. 6662 if True: 6663 # Collect param values. 6664 selections = [':2,3'] 6665 for selection in selections: 6666 analysis = 'min' 6667 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6668 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6669 6670 # Get param stats. 6671 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6672 6673 ## Plot R2eff stats 6674 write_stats = True 6675 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6676 6677 # Open stat file. 6678 if write_stats: 6679 if selection == None: 6680 file_name = '%s_stat_all.txt' % (analysis) 6681 else: 6682 file_name = '%s_stat_sel.txt' % (analysis) 6683 path = RDR.results_dir 6684 data = extract_data(file=file_name, dir=path) 6685 6686 # Loop over the lines. 6687 for i, data_i in enumerate(data): 6688 print(i, data_i)
6689 6690 6691
6692 - def test_r1rho_kjaergaard_auto(self):
6693 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6694 6695 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6696 6697 This uses the automatic analysis. 6698 6699 """ 6700 6701 # Cluster residues 6702 cluster_ids = [ 6703 ":13@N", 6704 ":15@N", 6705 ":16@N", 6706 ":25@N", 6707 ":26@N", 6708 ":28@N", 6709 ":39@N", 6710 ":40@N", 6711 ":41@N", 6712 ":43@N", 6713 ":44@N", 6714 ":45@N", 6715 ":49@N", 6716 ":52@N", 6717 ":53@N"] 6718 6719 # Load the data. 6720 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6721 6722 # Test some of the sequence. 6723 self.assertEqual(len(cdp.mol), 1) 6724 self.assertEqual(cdp.mol[0].name, None) 6725 self.assertEqual(len(cdp.mol[0].res), 48) 6726 6727 # Test the chemical shift data. 6728 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6729 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6730 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6731 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 6732 6733 i = 0 6734 for spin, spin_id in spin_loop(return_id=True): 6735 # Check the chemical shift. 6736 self.assertEqual(spin.chemical_shift, cs[i]) 6737 6738 # Increment the index. 6739 i += 1 6740 6741 # Initialize counter 6742 i = 0 6743 j = 0 6744 # Count instances of select/deselect 6745 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6746 if curspin.select == True: 6747 i += 1 6748 if curspin.select == False: 6749 j += 1 6750 6751 # Test number of selected/deselected spins. 6752 self.assertEqual(i, len(cluster_ids)) 6753 self.assertEqual(j, 48-len(cluster_ids)) 6754 6755 # Check the initial setup. 6756 self.assertEqual(cdp.mol[0].res[7].num, 13) 6757 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6758 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6759 6760 self.assertEqual(cdp.mol[0].res[9].num, 15) 6761 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6762 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6763 6764 self.assertEqual(cdp.mol[0].res[10].num, 16) 6765 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6766 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6767 6768 self.assertEqual(cdp.mol[0].res[16].num, 25) 6769 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6770 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6771 6772 self.assertEqual(cdp.mol[0].res[17].num, 26) 6773 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6774 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6775 6776 self.assertEqual(cdp.mol[0].res[19].num, 28) 6777 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6778 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6779 6780 self.assertEqual(cdp.mol[0].res[29].num, 39) 6781 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6782 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6783 6784 self.assertEqual(cdp.mol[0].res[30].num, 40) 6785 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6786 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6787 6788 self.assertEqual(cdp.mol[0].res[31].num, 41) 6789 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6790 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6791 6792 self.assertEqual(cdp.mol[0].res[33].num, 43) 6793 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6794 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6795 6796 self.assertEqual(cdp.mol[0].res[34].num, 44) 6797 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6798 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6799 6800 self.assertEqual(cdp.mol[0].res[35].num, 45) 6801 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6802 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6803 6804 self.assertEqual(cdp.mol[0].res[38].num, 49) 6805 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6806 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6807 6808 self.assertEqual(cdp.mol[0].res[41].num, 52) 6809 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6810 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6811 6812 self.assertEqual(cdp.mol[0].res[42].num, 53) 6813 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6814 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6815 6816 # The dispersion models. 6817 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6818 6819 # The grid search size (the number of increments per dimension). 6820 GRID_INC = 4 6821 6822 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6823 MC_NUM = 3 6824 6825 # Model selection technique. 6826 MODSEL = 'AIC' 6827 6828 # Execute the auto-analysis (fast). 6829 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6830 OPT_FUNC_TOL = 1e-1 6831 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6832 OPT_MAX_ITERATIONS = 1000 6833 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6834 6835 result_dir_name = ds.tmpdir 6836 6837 # Make all spins free 6838 for curspin in cluster_ids: 6839 self.interpreter.relax_disp.cluster('free spins', curspin) 6840 # Shut them down 6841 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6842 6843 # Select only a subset of spins for global fitting 6844 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6845 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6846 6847 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6848 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6849 6850 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6851 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6852 6853 # Run the analysis. 6854 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6855 6856 # Check the kex value of residue 52 6857 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6858 6859 # Print results for each model. 6860 print("\n\n################") 6861 print("Printing results") 6862 print("################\n") 6863 for model in MODELS: 6864 # Skip R2eff model. 6865 if model == MODEL_R2EFF: 6866 continue 6867 6868 # Switch to pipe. 6869 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6870 print("\nModel: %s" % (model)) 6871 6872 # Loop over the spins. 6873 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6874 # Generate spin string. 6875 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6876 6877 # Loop over the parameters. 6878 print("Optimised parameters for spin: %s" % (spin_string)) 6879 for param in cur_spin.params + ['chi2']: 6880 # Get the value. 6881 if param in ['r1', 'r2']: 6882 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6883 # Generate the R20 key. 6884 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6885 6886 # Get the value. 6887 value = getattr(cur_spin, param)[r20_key] 6888 6889 # Print value. 6890 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6891 6892 # For all other parameters. 6893 else: 6894 # Get the value. 6895 value = getattr(cur_spin, param) 6896 6897 # Print value. 6898 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6899 6900 # Print the final pipe. 6901 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 6902 print("\nFinal pipe")
6903 6904
6906 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 6907 6908 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6909 6910 This uses the automatic analysis. 6911 6912 """ 6913 6914 # Cluster residues 6915 cluster_ids = [ 6916 ":52@N"] 6917 6918 # Load the data. 6919 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6920 6921 # The dispersion models. 6922 MODELS = [MODEL_R2EFF] 6923 6924 # The grid search size (the number of increments per dimension). 6925 GRID_INC = 4 6926 6927 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6928 MC_NUM = 3 6929 6930 # Model selection technique. 6931 MODSEL = 'AIC' 6932 6933 # Execute the auto-analysis (fast). 6934 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6935 OPT_FUNC_TOL = 1e-1 6936 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6937 OPT_MAX_ITERATIONS = 1000 6938 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6939 6940 result_dir_name = ds.tmpdir 6941 6942 # Make all spins free 6943 for curspin in cluster_ids: 6944 self.interpreter.relax_disp.cluster('free spins', curspin) 6945 # Shut them down 6946 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6947 6948 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6949 6950 # Run the analysis. 6951 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6952 6953 # Check the graphs produced. 6954 graph_comb = [ 6955 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 6956 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 6957 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 6958 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 6959 ] 6960 6961 # Define expected folder names. 6962 result_folders = MODELS 6963 6964 # Assign spin_id. 6965 spin_id = ':52@N' 6966 6967 # Loop over result folders. 6968 for result_folder in result_folders: 6969 # Skip the model R2eff, which does not produce graphs. 6970 if result_folder == MODEL_R2EFF: 6971 continue 6972 6973 # Loop over graphs. 6974 for y_axis, x_axis, interpolate in graph_comb: 6975 # Determine file name: 6976 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6977 6978 # Make the file name. 6979 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6980 6981 # Get the file path. 6982 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 6983 6984 print("Testing file access to graph: %s"%file_path) 6985 self.assert_(access(file_path, F_OK)) 6986 6987 # Start testing all possible combinations of graphs. 6988 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 6989 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 6990 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 6991 6992 result_dir_name = ds.tmpdir 6993 6994 # Loop through all possible combinations of y_axis, x_axis and interpolation. 6995 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 6996 6997 for result_folder in result_folders: 6998 # Skip the model R2eff, which does not produce graphs. 6999 if result_folder == MODEL_R2EFF: 7000 continue 7001 7002 for y_axis in y_axis_types: 7003 for x_axis in x_axis_types: 7004 for interpolate in interpolate_types: 7005 # Determine file name: 7006 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7007 7008 # Make the file name. 7009 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7010 7011 # Write the curves. 7012 dir = result_dir_name+sep+result_folder 7013 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7014 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7015 7016 # Get the file path. 7017 file_path = get_file_path(file_name, dir) 7018 7019 # Test the plot file exists. 7020 print("Testing file access to graph: %s"%file_path) 7021 self.assert_(access(file_path, F_OK)) 7022 7023 # Now open, and compare content, line by line. 7024 file_prod = open(file_path) 7025 lines_prod = file_prod.readlines() 7026 file_prod.close() 7027 7028 # Define file to compare against. 7029 dir_comp = data_path+sep+result_folder 7030 file_path_comp = get_file_path(file_name, dir_comp) 7031 file_comp = open(file_path_comp) 7032 lines_comp = file_comp.readlines() 7033 file_comp.close() 7034 7035 # Assert number of lines is equal. 7036 self.assertEqual(len(lines_prod), len(lines_comp)) 7037 for j in range(len(lines_prod)): 7038 # Make the string test 7039 first_char = lines_prod[j][0] 7040 if first_char in ["@", "&"]: 7041 self.assertEqual(lines_prod[j], lines_comp[j]) 7042 else: 7043 # Split string in x, y, error. 7044 # The error would change per run. 7045 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7046 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7047 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7048 self.assertAlmostEqual(float(y_prod), float(y_comp))
7049 7050
7052 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7053 7054 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7055 7056 This uses the automatic analysis, with missing loading R1. 7057 7058 """ 7059 7060 # Cluster residues 7061 cluster_ids = [ 7062 ":13@N", 7063 ":15@N", 7064 ":16@N", 7065 ":25@N", 7066 ":26@N", 7067 ":28@N", 7068 ":39@N", 7069 ":40@N", 7070 ":41@N", 7071 ":43@N", 7072 ":44@N", 7073 ":45@N", 7074 ":49@N", 7075 ":52@N", 7076 ":53@N"] 7077 7078 # Load the data. 7079 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7080 7081 # The dispersion models. 7082 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7083 7084 # The grid search size (the number of increments per dimension). 7085 GRID_INC = None 7086 7087 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7088 MC_NUM = 3 7089 7090 # Model selection technique. 7091 MODSEL = 'AIC' 7092 7093 # Execute the auto-analysis (fast). 7094 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7095 OPT_FUNC_TOL = 1e-25 7096 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7097 OPT_MAX_ITERATIONS = 10000000 7098 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7099 7100 result_dir_name = ds.tmpdir 7101 7102 # Make all spins free 7103 for curspin in cluster_ids: 7104 self.interpreter.relax_disp.cluster('free spins', curspin) 7105 # Shut them down 7106 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7107 7108 # Select only a subset of spins for global fitting 7109 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7110 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7111 7112 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7113 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7114 7115 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7116 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7117 7118 # Point to directory with R2eff values, with 2000 MC simulations. 7119 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7120 7121 r1_fit = True 7122 7123 # Run the analysis. 7124 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7125 7126 # Verify the data. 7127 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7128 7129
7130 - def test_r2eff_read(self):
7131 """Test the operation of the relax_disp.r2eff_read user function.""" 7132 7133 # The path to the data files. 7134 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7135 7136 # Read the sequence data. 7137 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7138 7139 # The ID. 7140 id = 'test' 7141 7142 # Set up the metadata. 7143 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7144 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7145 7146 # Try reading the file. 7147 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7148 7149 # Check the global data. 7150 data = [ 7151 ['cpmg_frqs', {'test': 66.667}], 7152 ['cpmg_frqs_list', [66.667]], 7153 ['dispersion_points', 1], 7154 ['exp_type', {'test': 'SQ CPMG'}], 7155 ['exp_type_list', ['SQ CPMG']], 7156 ['spectrometer_frq', {'test': 800000000.0}], 7157 ['spectrometer_frq_count', 1], 7158 ['spectrometer_frq_list', [800000000.0]], 7159 ['spectrum_ids', ['test']] 7160 ] 7161 for name, value in data: 7162 # Does it exist? 7163 self.assert_(hasattr(cdp, name)) 7164 7165 # Check the object. 7166 obj = getattr(cdp, name) 7167 self.assertEqual(obj, value) 7168 7169 # Check the spin data. 7170 data = [ 7171 [1, 2.3035747e+04, 8.5467725e+01], 7172 [2, 9.9629762e+04, 2.8322033e+02], 7173 [3, 9.5663137e+04, 2.8632929e+02], 7174 [4, 1.7089893e+05, 3.1089428e+02], 7175 [5, 4.7323876e+04, 1.0084269e+02], 7176 [6, 2.0199122e+04, 1.0135220e+02], 7177 [7, 1.6655488e+05, 3.1609061e+02], 7178 [8, 9.0061074e+04, 1.9176585e+02], 7179 [10, 8.4726204e+04, 2.8898155e+02], 7180 [11, 1.5050233e+05, 4.3138029e+02], 7181 [12, 9.2998531e+04, 3.0440191e+02], 7182 [13, 1.6343507e+05, 3.3144097e+02], 7183 [14, 1.0137301e+05, 3.7314642e+02], 7184 [15, 8.3407837e+04, 1.6546473e+02], 7185 [16, 1.3819126e+05, 3.3388517e+02], 7186 [17, 1.1010490e+05, 3.5639222e+02], 7187 [18, 9.4324035e+04, 3.2343585e+02], 7188 [19, 1.1135179e+05, 3.0706671e+02], 7189 [20, 7.6339410e+04, 1.7377460e+02], 7190 [21, 6.2008453e+04, 1.7327150e+02], 7191 [22, 1.0590404e+05, 2.4814635e+02], 7192 [23, 1.0630198e+05, 2.3601100e+02], 7193 [24, 7.2996320e+04, 1.4952465e+02], 7194 [25, 9.5486742e+04, 2.7080766e+02], 7195 [26, 5.8067989e+04, 1.6820462e+02], 7196 [27, -1.7168510e+04, 2.2519560e+02], 7197 [28, 1.6891473e+05, 2.3497525e+02], 7198 [29, 9.4038555e+04, 2.0357593e+02], 7199 [30, 2.1386951e+04, 2.2153532e+02], 7200 [31, 9.3982899e+04, 2.0937056e+02], 7201 [32, 8.6097484e+04, 2.3868467e+02], 7202 [33, 1.0194337e+05, 2.7370704e+02], 7203 [34, 8.5683111e+04, 2.0838076e+02], 7204 [35, 8.6985768e+04, 2.0889310e+02], 7205 [36, 8.6011237e+04, 1.7498390e+02], 7206 [37, 1.0984097e+05, 2.7622998e+02], 7207 [38, 8.7017879e+04, 2.6547994e+02], 7208 [39, 9.1682649e+04, 5.2777676e+02], 7209 [40, 7.6370440e+04, 1.9873214e+02], 7210 [41, 9.1393531e+04, 2.4483824e+02], 7211 [42, 1.1017111e+05, 2.8020699e+02], 7212 [43, 9.4552366e+04, 3.4394150e+02], 7213 [44, 1.2858281e+05, 6.8449252e+02], 7214 [45, 7.4583525e+04, 1.9544210e+02], 7215 [46, 9.2087490e+04, 2.0491066e+02], 7216 [47, 9.7507255e+04, 2.5162839e+02], 7217 [48, 1.0033842e+05, 2.7566430e+02], 7218 [49, 1.3048305e+05, 2.6797466e+02], 7219 [50, 1.0546796e+05, 1.9304384e+02], 7220 [51, 9.3099697e+04, 2.0773311e+02], 7221 [52, 4.6863758e+04, 1.3169068e+02], 7222 [53, 6.1055806e+04, 1.5448477e+02], 7223 [55, 6.8629994e+04, 1.6868673e+02], 7224 [56, 1.1005552e+05, 2.1940465e+02], 7225 [57, 1.0572760e+05, 1.9768486e+02], 7226 [58, 1.1176950e+05, 3.0009610e+02], 7227 [59, 9.8758603e+04, 3.3803895e+02], 7228 [60, 9.9517201e+04, 3.5137994e+02], 7229 [61, 5.4357946e+04, 2.5896579e+02], 7230 [62, 1.0899978e+05, 2.8720371e+02], 7231 [63, 8.4549759e+04, 4.1401837e+02], 7232 [64, 5.5014550e+04, 2.1135781e+02], 7233 [65, 8.0569666e+04, 2.3249709e+02], 7234 [66, 1.2936610e+05, 3.5218725e+02], 7235 [67, 3.6438010e+04, 8.7924003e+01], 7236 [70, 3.8763157e+04, 1.3325040e+02], 7237 [71, 8.5711411e+04, 2.9316183e+02], 7238 [72, 3.3211541e+04, 1.2182123e+02], 7239 [73, 3.2070576e+04, 1.2305430e+02] 7240 ] 7241 for res_num, value, error in data: 7242 # Get the spin. 7243 spin = return_spin(spin_id=":%s"%res_num) 7244 7245 # Check the values. 7246 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7247 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7248 7249
7250 - def test_r2eff_read_spin(self):
7251 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7252 7253 # The path to the data files. 7254 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7255 7256 # Generate the sequence. 7257 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7258 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7259 self.interpreter.spin.isotope('1H', spin_id='@H') 7260 self.interpreter.spin.isotope('15N', spin_id='@N') 7261 7262 # Build the experiment IDs. 7263 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7264 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7265 ids = [] 7266 for value in H_disp_points: 7267 ids.append('1H_CPMG_%s' % value) 7268 for value in N_disp_points: 7269 ids.append('15N_CPMG_%s' % value) 7270 print("\n\nThe experiment IDs are %s." % ids) 7271 7272 # Set up the metadata for the experiments. 7273 for id in ids: 7274 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7275 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7276 for value in H_disp_points: 7277 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7278 for value in N_disp_points: 7279 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7280 7281 # Loop over the experiments. 7282 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7283 # Try reading the file. 7284 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7285 7286 # Check the global data. 7287 data = [ 7288 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7289 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7290 ['dispersion_points', 24], 7291 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7292 ['exp_type_list', ['SQ CPMG']], 7293 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7294 ['spectrometer_frq_count', 1], 7295 ['spectrometer_frq_list', [500000000.0]], 7296 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7297 ] 7298 for name, value in data: 7299 # Does it exist? 7300 self.assert_(hasattr(cdp, name)) 7301 7302 # Check the object. 7303 obj = getattr(cdp, name) 7304 if not isinstance(data, dict): 7305 self.assertEqual(obj, value) 7306 7307 # Check the global dictionary data. 7308 else: 7309 for id in ids: 7310 self.assertEqual(obj[id], value[id]) 7311 7312 # Check the spin data. 7313 h_data = [ 7314 [ 67.0, 21.47924, 0.42958], 7315 [ 133.0, 16.73898, 0.33478], 7316 [ 267.0, 9.97357, 0.19947], 7317 [ 400.0, 8.23877, 0.24737], 7318 [ 533.0, 7.59290, 0.24263], 7319 [ 667.0, 7.45843, 0.24165], 7320 [ 800.0, 7.11222, 0.23915], 7321 [ 933.0, 7.40880, 0.24129], 7322 [1067.0, 6.55191, 0.16629], 7323 [1600.0, 6.72177, 0.23637], 7324 [2133.0, 7.09629, 0.23904], 7325 [2667.0, 7.14675, 0.23940] 7326 ] 7327 for disp_point, value, error in h_data: 7328 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7329 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7330 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7331 n_data = [ 7332 [ 50.0, 27.15767, 0.54315], 7333 [ 100.0, 26.55781, 0.53116], 7334 [ 150.0, 24.73462, 0.49469], 7335 [ 200.0, 20.98617, 0.41972], 7336 [ 250.0, 17.82442, 0.35649], 7337 [ 300.0, 15.55352, 0.31107], 7338 [ 350.0, 13.78958, 0.27579], 7339 [ 400.0, 12.48334, 0.24967], 7340 [ 500.0, 11.55724, 0.23114], 7341 [ 600.0, 10.53874, 0.21077], 7342 [ 700.0, 10.07395, 0.20148], 7343 [ 800.0, 9.62952, 0.19259], 7344 [ 900.0, 9.49994, 0.19000], 7345 [1000.0, 8.71350, 0.17427] 7346 ] 7347 for disp_point, value, error in n_data: 7348 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7349 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7350 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7351 7352
7353 - def test_r2eff_fit_fixed_time(self):
7354 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7355 7356 # Execute the script. 7357 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7358 7359
7360 - def test_read_r2eff(self):
7361 """Test the reading of a file containing r2eff values.""" 7362 7363 # Create the sequence data, and name the spins. 7364 self.interpreter.residue.create(1, 'Gly') 7365 self.interpreter.residue.create(2, 'Gly') 7366 self.interpreter.residue.create(3, 'Gly') 7367 7368 # Read the file. 7369 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7370 7371 # Test the data. 7372 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7373 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7374 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7375 7376
7378 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7379 7380 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7381 7382 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7383 'SOD1-WT' CPMG data to the CR72 dispersion model. 7384 7385 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7386 Data is for experiment at 25 degree Celcius. 7387 """ 7388 7389 # Base data setup. 7390 pipe_name = 'base pipe' 7391 pipe_type = 'relax_disp' 7392 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7393 select_spin_index = list(range(0, 1)) 7394 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7395 7396 # Generate r20 key. 7397 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7398 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7399 7400 ## Now prepare for MODEL calculation. 7401 MODEL = "CR72" 7402 7403 # Change pipe. 7404 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7405 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7406 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7407 7408 # Then select model. 7409 self.interpreter.relax_disp.select_model(model=MODEL) 7410 7411 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7412 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7413 7414 # Test result, for normal run. 7415 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7416 # Get the spin_params. 7417 spin_params = spin.params 7418 7419 # Defined fixed values for testing. 7420 if spin_id == ":10@N": 7421 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7422 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7423 7424 # Print out. 7425 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7426 7427 # Testing the r2 values for the different fields are not the same. 7428 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7429 7430 # Test values are larger than 0. 7431 self.assert_(spin.r2[r20_key_600] > 0.0) 7432 self.assert_(spin.r2[r20_key_500] > 0.0) 7433 7434 # Loop over the experiment settings. 7435 r2eff_600 = [] 7436 r2eff_500 = [] 7437 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7438 # Create the data key. 7439 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7440 7441 # Extract the r2 eff data. 7442 r2eff = spin.r2eff[data_key] 7443 if frq == 599.8908617*1E6: 7444 r2eff_600.append(r2eff) 7445 elif frq == 499.862139*1E6: 7446 r2eff_500.append(r2eff) 7447 7448 # Sort values. 7449 r2eff_600.sort() 7450 r2eff_500.sort() 7451 7452 # Test values again. 7453 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7454 print(r2eff_600) 7455 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7456 print("") 7457 7458 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7459 print(r2eff_500) 7460 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7461 print("") 7462 7463 print("###########################################") 7464 print("Trying GRID SEARCH for minimum R2eff values") 7465 7466 ### Test just the Grid search. 7467 GRID_INC = 5 7468 7469 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7470 7471 ### Then test the value.set function. 7472 # Change pipe. 7473 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7474 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7475 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7476 7477 # Then select model. 7478 self.interpreter.relax_disp.select_model(model=MODEL) 7479 7480 # Then set the standard parameter values. 7481 for param in spin_params: 7482 print("Setting standard parameter for param: %s"%param) 7483 self.interpreter.value.set(param=param, index=None) 7484 7485 # Test result, for normal run. 7486 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7487 # Print out. 7488 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7489 7490 # Testing the r2 values. 7491 self.assertEqual(spin.r2[r20_key_600], 10.00) 7492 self.assertEqual(spin.r2[r20_key_500], 10.00) 7493 self.assertEqual(spin.pA, 0.9) 7494 self.assertEqual(spin.dw, 1.0) 7495 self.assertEqual(spin.kex, 1000.0) 7496 7497 print("###########################################") 7498 print("Trying GRID SEARCH for standard R2eff values") 7499 7500 ### Test just the Grid search. 7501 GRID_INC = 5 7502 7503 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7504 7505 ### Run auto_analysis. 7506 # The grid search size (the number of increments per dimension). 7507 GRID_INC = 5 7508 7509 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7510 MC_NUM = 3 7511 7512 # Model selection technique. 7513 MODSEL = 'AIC' 7514 7515 # Execute the auto-analysis (fast). 7516 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7517 OPT_FUNC_TOL = 1e-1 7518 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7519 OPT_MAX_ITERATIONS = 1000 7520 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7521 7522 # Run the analysis. 7523 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7524 7525
7526 - def test_show_apod_extract(self):
7527 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7528 7529 # The path to the data files. 7530 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7531 7532 # Define file name. 7533 file_name = '128_0_FT.ft2' 7534 7535 # Call function. 7536 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7537 7538 # Define how output should look like. 7539 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7540 # Dont test lines which can differ. 7541 show_apod_ver = [ 7542 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7543 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7544 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7545 '', 7546 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7547 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7548 #'', 7549 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7550 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7551 7552 for i, line in enumerate(show_apod_ver): 7553 line_ver = get_output[i] 7554 7555 print(line) 7556 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7557 continue 7558 # Make the string test 7559 self.assertEqual(line, line_ver)
7560 7561
7562 - def test_show_apod_rmsd(self):
7563 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7564 7565 # The path to the data files. 7566 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7567 7568 # Define file name. 7569 file_name = '128_0_FT.ft2' 7570 7571 # Call function. 7572 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7573 7574 # Assert. 7575 self.assertEqual(rmsd, 8583.41)
7576 7577
7579 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7580 7581 # The path to the data files. 7582 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7583 7584 # Call function, and get all file names. 7585 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7586 7587 # Loop over file_paths. 7588 for wfile_path in wfile_paths: 7589 # Open the file. 7590 get_data = extract_data(file=wfile_path) 7591 7592 # Extract line 0, column 0. 7593 test = float(get_data[0][0]) 7594 7595 # Assert. 7596 self.assertEqual(test, 8583.41)
7597 7598
7600 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7601 7602 # The path to the data files. 7603 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7604 7605 # Define file name. 7606 file_name = '128_0_FT.ft2' 7607 7608 # Call function, and get file name. 7609 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7610 7611 # Open the file. 7612 get_data = extract_data(file=wfile_path) 7613 7614 # Extract line 0, column 0. 7615 test = float(get_data[0][0]) 7616 7617 # Assert. 7618 self.assertEqual(test, 8583.41)
7619 7620
7622 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7623 7624 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7625 'SOD1-WT' CPMG data to the CR72 dispersion model. 7626 7627 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7628 Data is for experiment at 25 degree Celcius. 7629 7630 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7631 """ 7632 7633 # Base data setup. 7634 pipe_name = 'base pipe' 7635 pipe_type = 'relax_disp' 7636 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7637 select_spin_index = list(range(0, 1)) 7638 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7639 7640 # Define replicated 7641 repl_A = ['Z_A1', 'Z_A15'] 7642 repl_B = ['Z_B1', 'Z_B18'] 7643 7644 # Loop over spectrum ID, and sort them 7645 spectrum_ids_A = [] 7646 spectrum_ids_B = [] 7647 for spectrum_id in cdp.spectrum_ids: 7648 if "A" in spectrum_id: 7649 spectrum_ids_A.append(spectrum_id) 7650 elif "B" in spectrum_id: 7651 spectrum_ids_B.append(spectrum_id) 7652 7653 # To clean up old error analysis, delete attributes 7654 delattr(cdp, "var_I") 7655 delattr(cdp, "sigma_I") 7656 7657 # Perform error analysis 7658 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7659 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7660 7661 # Loop over spins, save errors to list 7662 Errors_A_B = [] 7663 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7664 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7665 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7666 Errors_A_B.append([A_err, B_err]) 7667 7668 # To clean up old error analysis, delete attributes 7669 delattr(cdp, "var_I") 7670 delattr(cdp, "sigma_I") 7671 7672 # Perform error analysis. Order is important 7673 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7674 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7675 7676 # Loop over spins, save errors to list 7677 Errors_B_A = [] 7678 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7679 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7680 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7681 Errors_B_A.append([A_err, B_err]) 7682 7683 # Make test for order of error 7684 for i in range(len(Errors_A_B)): 7685 Error_A_B = Errors_A_B[i] 7686 Error_B_A = Errors_B_A[i] 7687 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7688 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7689 7690 # Make further tests for fixed values 7691 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7692 std_A_fix = 2785.7263335738567 7693 7694 for id_A in spectrum_ids_A: 7695 self.assertEqual(cdp.sigma_I[id_A], std_A) 7696 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7697 7698 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7699 std_B_fix = 4967.3772030667988 7700 7701 for id_B in spectrum_ids_B: 7702 self.assertEqual(cdp.sigma_I[id_B], std_B) 7703 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7704 7705
7706 - def test_sod1wt_t25_to_cr72(self):
7707 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7708 7709 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7710 'SOD1-WT' CPMG data to the CR72 dispersion model. 7711 7712 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7713 Data is for experiment at 25 degree Celcius. 7714 """ 7715 7716 # Base data setup. 7717 pipe_name = 'base pipe' 7718 pipe_type = 'relax_disp' 7719 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7720 select_spin_index = list(range(0, 2)) 7721 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7722 7723 # Generate r20 key. 7724 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7725 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7726 7727 ## Now prepare for MODEL calculation. 7728 MODEL = "CR72" 7729 7730 # Change pipe. 7731 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7732 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7733 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7734 7735 # Then select model. 7736 self.interpreter.relax_disp.select_model(model=MODEL) 7737 7738 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7739 GRID_INC = 7 7740 7741 # Store grid and minimisations results. 7742 grid_results = [] 7743 mini_results = [] 7744 clust_results = [] 7745 7746 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7747 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7748 7749 # Deselect insignificant spins. 7750 self.interpreter.relax_disp.insignificance(level=1.0) 7751 7752 # Perform Grid Search. 7753 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7754 7755 # Store result. 7756 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7757 # Store grid results. 7758 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7759 7760 ## Now do minimisation. 7761 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7762 set_func_tol = 1e-9 7763 set_max_iter = 100000 7764 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7765 7766 # Store result. 7767 pA_values = [] 7768 kex_values = [] 7769 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7770 # Store minimisation results. 7771 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7772 7773 # Store pA values. 7774 pA_values.append(spin.pA) 7775 7776 # Store kex values. 7777 kex_values.append(spin.kex) 7778 7779 print("\n# Now print before and after minimisation.\n") 7780 7781 # Print results. 7782 for i in range(len(grid_results)): 7783 # Get values. 7784 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7785 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7786 7787 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7788 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7789 7790 ## Prepare for clustering 7791 # Change pipe. 7792 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7793 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7794 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7795 7796 # Then select model. 7797 self.interpreter.relax_disp.select_model(model=MODEL) 7798 7799 # Define cluster id. 7800 cluster_id = 'clust' 7801 7802 # Loop over spins to cluster them. 7803 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7804 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7805 7806 # Copy over values. 7807 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7808 7809 # Test the median values is correct 7810 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7811 print(pA_values) 7812 # The the median pA value returned. 7813 self.assertEqual(median(pA_values), spin.pA) 7814 7815 # The the median kex value returned. 7816 self.assertEqual(median(kex_values), spin.kex) 7817 7818 ## Now do minimisation. 7819 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7820 7821 # Store result. 7822 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7823 # Store clust results. 7824 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7825 7826 # Store the outcome of the clustering minimisation. 7827 clust_pA = spin.pA 7828 clust_kex = spin.kex 7829 7830 print("\n# Now testing.\n") 7831 7832 # Define results 7833 test_res = {} 7834 test_res[':10@N'] = {} 7835 test_res[':10@N']['r2600'] = 18.429755324773360 7836 test_res[':10@N']['r2500'] = 16.981349161968630 7837 test_res[':10@N']['dw'] = 2.700755859433969 7838 test_res[':10@N']['pA'] = 0.971531659288657 7839 test_res[':10@N']['kex'] = 3831.766337047963134 7840 test_res[':11@N'] = {} 7841 test_res[':11@N']['r2600'] = 18.193409421115213 7842 test_res[':11@N']['r2500'] = 17.308838135567765 7843 test_res[':11@N']['dw'] = 2.706650302761793 7844 test_res[':11@N']['pA'] = 0.971531659288657 7845 test_res[':11@N']['kex'] = 3831.766337047963134 7846 7847 # Then make tests. 7848 for i in range(len(grid_results)): 7849 # Get values. 7850 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7851 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7852 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7853 7854 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7855 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7856 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 7857 7858 # Make tests. 7859 self.assertEqual(clust_pA, c_pA) 7860 self.assertEqual(clust_kex, c_kex) 7861 7862 # Test values. 7863 if c_spin_id in test_res: 7864 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7865 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7866 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7867 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7868 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7869 7870 # Save disp graph to temp. 7871 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7872 7873
7875 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7876 7877 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7878 'SOD1-WT' CPMG data to the CR72 dispersion model. 7879 7880 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7881 Data is for experiment at 25 degree Celcius. 7882 """ 7883 7884 # Base data setup. 7885 pipe_name = 'base pipe' 7886 pipe_type = 'relax_disp' 7887 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7888 select_spin_index = list(range(0, 2)) 7889 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7890 7891 # Generate r20 key. 7892 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7893 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7894 7895 # Cluster everything, to analyse together. 7896 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 7897 7898 # Write input 7899 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 7900 7901 # Check the r2eff set files. 7902 print("\nChecking the R2eff input set files.") 7903 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 7904 7905 # First check file exists 7906 for dir, file in files: 7907 print(dir+sep+file) 7908 self.assert_(access(dir+sep+file, F_OK)) 7909 7910 # Define how files should look like 7911 data_set_600 = [ 7912 "60.8272464287\n", 7913 "0.06\n", 7914 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7915 "# G10\n", 7916 " 33.333 26.53556078711 0.5236104771163\n", 7917 " 66.667 25.29735243318 0.48766574122\n", 7918 " 100 25.09470361403 0.4820438864671\n", 7919 " 133.333 25.15603274331 0.4837377286085\n", 7920 " 166.667 24.27213341753 0.4599457904395\n", 7921 " 200 24.00364120328 0.4529773198905\n", 7922 " 266.667 24.03511395168 0.4537880662536\n", 7923 " 300 23.04761040024 0.4291039120557\n", 7924 " 333.333 22.95530300787 0.4268745963972\n", 7925 " 400 23.06158810662 0.4294426293624\n", 7926 " 466.667 22.26799054092 0.4106809618644\n", 7927 " 533.333 21.99851418823 0.4045232104735\n", 7928 " 666.667 21.19651570955 0.3868136173831\n", 7929 " 833.333 20.30938498379 0.3682604887899\n", 7930 " 1000 20.28273252609 0.367719392568\n", 7931 "# D11\n", 7932 " 33.333 24.76520269878 0.5026475808706\n", 7933 " 66.667 24.8773107448 0.5058752916906\n", 7934 " 100 24.90357815239 0.5066348551479\n", 7935 " 133.333 23.7782506151 0.4751950583865\n", 7936 " 166.667 23.68548762076 0.4727017128631\n", 7937 " 200 23.58629651618 0.4700517377679\n", 7938 " 266.667 23.47734671187 0.4671601744044\n", 7939 " 300 24.08647493772 0.4835855560598\n", 7940 " 333.333 22.98314371029 0.4542918950801\n", 7941 " 400 22.80339361568 0.4497107885587\n", 7942 " 466.667 22.91634335366 0.4525833037874\n", 7943 " 533.333 22.59774140046 0.4445334311324\n", 7944 " 666.667 20.9177750759 0.4046955726046\n", 7945 " 833.333 20.71792550566 0.4002363835007\n", 7946 " 1000 19.54080006349 0.3751112751853\n", 7947 ] 7948 7949 # Check data_set_600 7950 file = open(files[0][0]+sep+files[0][1]) 7951 lines = file.readlines() 7952 file.close() 7953 self.assertEqual(len(data_set_600), len(lines)) 7954 for i in range(len(data_set_600)): 7955 # Make the string test 7956 self.assertEqual(data_set_600[i], lines[i]) 7957 7958 # Define how files should look like 7959 data_set_500 = [ 7960 "50.6846152368\n", 7961 "0.04\n", 7962 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7963 "# G10\n", 7964 " 50 22.28084307393 0.2944966344183\n", 7965 " 100 21.93494977761 0.2910362768307\n", 7966 " 150 21.09850032232 0.282892238351\n", 7967 " 200 20.86493960397 0.2806737853646\n", 7968 " 250 20.75287269752 0.2796178205016\n", 7969 " 300 20.25597152406 0.2750013546989\n", 7970 " 350 19.92172163467 0.2719555756504\n", 7971 " 400 19.97712052922 0.272457105051\n", 7972 " 450 19.46807010415 0.2678972122793\n", 7973 " 500 19.76875460947 0.2705774849203\n", 7974 " 550 19.39161367402 0.2672216964327\n", 7975 " 600 19.03949517697 0.2641417899694\n", 7976 " 650 19.12218812132 0.2648605059901\n", 7977 " 700 19.01037461457 0.2638893584683\n", 7978 " 800 18.83395162904 0.2623674321143\n", 7979 " 900 18.47529972436 0.2593123604687\n", 7980 " 1000 18.5252023121 0.2597343394038\n", 7981 "# D11\n", 7982 " 50 22.15403890237 0.3285588379827\n", 7983 " 100 21.80946781746 0.3247185598713\n", 7984 " 150 21.77715415505 0.324361526682\n", 7985 " 200 21.41647464235 0.3204122024881\n", 7986 " 250 21.17099940822 0.3177616325958\n", 7987 " 300 21.03740030577 0.3163316496664\n", 7988 " 350 20.95393648281 0.3154427665172\n", 7989 " 400 20.93311399332 0.315221543436\n", 7990 " 450 20.18219905222 0.3073848655291\n", 7991 " 500 19.93599065085 0.3048744697057\n", 7992 " 550 19.68475725452 0.3023424499113\n", 7993 " 600 19.33575433934 0.2988741928798\n", 7994 " 650 19.53915692194 0.3008886196853\n", 7995 " 700 19.2018754351 0.2975587767134\n", 7996 " 800 18.82360965368 0.2938866923878\n", 7997 " 900 18.71861761238 0.2928790380131\n", 7998 " 1000 17.95878049287 0.2857341721151\n", 7999 ] 8000 8001 # Check data_set_500 8002 file = open(files[1][0]+sep+files[1][1]) 8003 lines = file.readlines() 8004 file.close() 8005 self.assertEqual(len(data_set_500), len(lines)) 8006 for i in range(len(data_set_500)): 8007 # Make the string test 8008 self.assertEqual(data_set_500[i], lines[i]) 8009 8010 # Test local dir tests. This will be turned off in system test. 8011 turn_on_local_dir_test = False 8012 8013 if turn_on_local_dir_test: 8014 ## Now check to local folder with None argument. 8015 # Write input 8016 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8017 8018 # Check the r2eff set files. 8019 print("\nChecking the R2eff input set files.") 8020 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8021 8022 # First check file exists 8023 for dir, file in files: 8024 print(dir+sep+file) 8025 self.assert_(access(dir+sep+file, F_OK)) 8026 8027 ## Now check to local folder with dir argument. 8028 # Write input 8029 set_dir = "Test_ShereKhan" 8030 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8031 8032 # Check the r2eff set files. 8033 print("\nChecking the R2eff input set files.") 8034 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8035 8036 # First check file exists 8037 for dir, file in files: 8038 print(dir+sep+file) 8039 self.assert_(access(dir+sep+file, F_OK))
8040 8041
8042 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8043 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8044 8045 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8046 """ 8047 8048 # Reset. 8049 self.interpreter.reset() 8050 8051 # Create the data pipe and load the base data. 8052 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8053 self.interpreter.state.load(data_path+sep+'r2eff_values') 8054 8055 # The model data pipe. 8056 model = 'MMQ CR72' 8057 pipe_name = "%s - relax_disp" % model 8058 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8059 self.interpreter.pipe.switch(pipe_name=pipe_name) 8060 8061 # Set the model. 8062 self.interpreter.relax_disp.select_model(model=model) 8063 8064 # Cluster everything. 8065 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8066 8067 # Copy the data. 8068 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8069 8070 # Alias the spins. 8071 spin135S = cdp.mol[0].res[0].spin[0] 8072 spin135F = cdp.mol[0].res[0].spin[1] 8073 spin137S = cdp.mol[0].res[1].spin[0] 8074 spin137F = cdp.mol[0].res[1].spin[1] 8075 8076 # The R20 keys. 8077 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8078 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8079 8080 # Set the cluster specific parameters (only for the first spin). 8081 spin135S.pA = 0.836591763632 8082 spin135S.kex = 241.806525261 8083 8084 # Set the initial parameter values. 8085 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8086 spin135S.dw = 0.583003118785 8087 spin135S.dwH = 0.0361441944301 8088 8089 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8090 spin135F.dw = 0.805849745104 8091 spin135F.dwH = 0.0215791945715 8092 8093 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8094 spin137S.dw = 0.688107568372 8095 spin137S.dwH = 0.0344463604043 8096 8097 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8098 spin137F.dw = 0.94978299907 8099 spin137F.dwH = 1.4818877939e-07 8100 8101 # Low precision optimisation. 8102 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8103 8104 # Printout. 8105 print("\n\nOptimised parameters:\n") 8106 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8107 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8108 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8109 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8110 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8111 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8112 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8113 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8114 print("\n # Set the cluster specific parameters (only for the first spin).") 8115 print(" spin135S.pA = %s" % spin135S.pA) 8116 print(" spin135S.kex = %s" % spin135S.kex) 8117 print("\n # Set the initial parameter values.") 8118 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8119 print(" spin135S.dw = %s" % spin135S.dw) 8120 print(" spin135S.dwH = %s" % spin135S.dwH) 8121 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8122 print(" spin135F.dw = %s" % spin135F.dw) 8123 print(" spin135F.dwH = %s" % spin135F.dwH) 8124 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8125 print(" spin137S.dw = %s" % spin137S.dw) 8126 print(" spin137S.dwH = %s" % spin137S.dwH) 8127 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8128 print(" spin137F.dw = %s" % spin137F.dw) 8129 print(" spin137F.dwH = %s" % spin137F.dwH) 8130 8131 # Checks for residue :135S. 8132 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8133 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8134 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8135 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8136 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8137 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8138 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8139 8140 # Checks for residue :135F. 8141 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8142 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8143 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8144 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8145 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8146 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8147 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8148 8149 # Checks for residue :137S. 8150 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8151 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8152 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8153 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8154 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8155 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8156 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8157 8158 # Checks for residue :137F. 8159 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8160 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8161 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8162 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8163 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8164 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8165 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8166 8167
8168 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8169 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8170 8171 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8172 """ 8173 8174 # Reset. 8175 self.interpreter.reset() 8176 8177 # Create the data pipe and load the base data. 8178 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8179 self.interpreter.state.load(data_path+sep+'r2eff_values') 8180 8181 # The model data pipe. 8182 model = 'NS MMQ 2-site' 8183 pipe_name = "%s - relax_disp" % model 8184 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8185 self.interpreter.pipe.switch(pipe_name=pipe_name) 8186 8187 # Set the model. 8188 self.interpreter.relax_disp.select_model(model=model) 8189 8190 # Cluster everything. 8191 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8192 8193 # Copy the data. 8194 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8195 8196 # Alias the spins. 8197 spin135S = cdp.mol[0].res[0].spin[0] 8198 spin135F = cdp.mol[0].res[0].spin[1] 8199 spin137S = cdp.mol[0].res[1].spin[0] 8200 spin137F = cdp.mol[0].res[1].spin[1] 8201 8202 # The R20 keys. 8203 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8204 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8205 8206 # Set the cluster specific parameters (only for the first spin). 8207 spin135S.pA = 0.847378444499757 8208 spin135S.kex = 264.055604934724329 8209 8210 # Set the initial parameter values. 8211 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8212 spin135S.dw = 0.585574008745351 8213 spin135S.dwH = 0.000000000000002 8214 8215 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8216 spin135F.dw = 0.856699277665748 8217 spin135F.dwH = 0.000000000582587 8218 8219 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8220 spin137S.dw = 0.772904450844973 8221 spin137S.dwH = 0.183351478512970 8222 8223 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8224 spin137F.dw = 0.984568590342831 8225 spin137F.dwH = 0.000000001993458 8226 8227 # Low precision optimisation. 8228 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8229 8230 # Printout. 8231 print("\n\nOptimised parameters:\n") 8232 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8233 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8234 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8235 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8236 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8237 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8238 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8239 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8240 8241 # FIXME: Remove this temporary return and properly check the results. 8242 return 8243 8244 # Checks for residue :135S. 8245 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8246 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8247 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8248 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8249 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8250 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8251 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8252 8253 # Checks for residue :135F. 8254 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8255 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8256 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8257 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8258 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8259 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8260 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8261 8262 # Checks for residue :137S. 8263 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8264 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8265 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8266 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8267 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8268 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8269 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8270 8271 # Checks for residue :137F. 8272 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8273 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8274 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8275 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8276 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8277 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8278 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8279 8280
8281 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8282 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8283 8284 # Setup the data. 8285 self.setup_tp02_data_to_ns_r1rho_2site() 8286 8287 # Alias the spins. 8288 spin1 = cdp.mol[0].res[0].spin[0] 8289 spin2 = cdp.mol[0].res[1].spin[0] 8290 8291 # The R20 keys. 8292 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8293 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8294 8295 # Checks for residue :1. 8296 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8297 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8298 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8299 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8300 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8301 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8302 8303 # Checks for residue :2. 8304 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8305 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8306 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8307 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8308 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8309 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8310 8311
8312 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8313 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8314 8315 # Setup the data. 8316 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8317 8318 # Alias the spins. 8319 spin1 = cdp.mol[0].res[0].spin[0] 8320 spin2 = cdp.mol[0].res[1].spin[0] 8321 8322 # The R20 keys. 8323 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8324 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8325 8326 # Checks for residue :1. 8327 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8328 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8329 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8330 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8331 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8332 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8333 8334 # Checks for residue :2. 8335 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8336 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8337 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8338 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8339 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8340 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8341 8342
8343 - def test_tp02_data_to_mp05(self):
8344 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8345 8346 # Fixed time variable and the models. 8347 ds.fixed = True 8348 ds.models = ['R2eff', 'MP05'] 8349 8350 # Execute the script. 8351 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8352 8353 # Switch back to the data pipe for the optimisation. 8354 self.interpreter.pipe.switch('MP05 - relax_disp') 8355 8356 # The equivalent MP05 parameters. 8357 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8358 pA = [0.775055484521586, 0.500000000036595] 8359 kex = [1235.20361276079, 2378.31403454691] 8360 delta_omega = [7.08194146569694, 5.4083562844306] 8361 chi2 = [0.0370400968727768, 0.182141732163934] 8362 8363 # Alias the spins. 8364 spin1 = cdp.mol[0].res[0].spin[0] 8365 spin2 = cdp.mol[0].res[1].spin[0] 8366 8367 # The R20 keys. 8368 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8369 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8370 8371 # Printout. 8372 print("\n\nOptimised parameters:\n") 8373 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8374 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8375 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8376 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8377 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8378 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8379 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8380 8381 # Check each spin. 8382 spin_index = 0 8383 for spin, spin_id in spin_loop(return_id=True): 8384 # Printout. 8385 print("\nSpin %s." % spin_id) 8386 8387 # Check the fitted parameters. 8388 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8389 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8390 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8391 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8392 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8393 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8394 8395 # Increment the spin index. 8396 spin_index += 1
8397 8398
8399 - def test_tp02_data_to_tap03(self):
8400 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8401 8402 # Fixed time variable and the models. 8403 ds.fixed = True 8404 ds.models = ['R2eff', 'TAP03'] 8405 8406 # Execute the script. 8407 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8408 8409 # Switch back to the data pipe for the optimisation. 8410 self.interpreter.pipe.switch('TAP03 - relax_disp') 8411 8412 # The equivalent TAP03 parameters. 8413 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8414 pA = [0.775042569092891, 0.500000000229685] 8415 kex = [1235.20852748765, 2379.47085580169] 8416 delta_omega = [7.08176806468445, 5.40708372863538] 8417 chi2 = [0.0371366837083293, 0.182212857256044] 8418 8419 # Alias the spins. 8420 spin1 = cdp.mol[0].res[0].spin[0] 8421 spin2 = cdp.mol[0].res[1].spin[0] 8422 8423 # The R20 keys. 8424 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8425 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8426 8427 # Printout. 8428 print("\n\nOptimised parameters:\n") 8429 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8430 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8431 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8432 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8433 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8434 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8435 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8436 8437 # Switch to the 'MP05' model data pipe, then check for each spin. 8438 self.interpreter.pipe.switch('TAP03 - relax_disp') 8439 spin_index = 0 8440 for spin, spin_id in spin_loop(return_id=True): 8441 # Printout. 8442 print("\nSpin %s." % spin_id) 8443 8444 # Check the fitted parameters. 8445 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8446 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8447 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8448 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8449 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8450 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8451 8452 # Increment the spin index. 8453 spin_index += 1
8454 8455
8456 - def test_tp02_data_to_tp02(self):
8457 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8458 8459 # Fixed time variable. 8460 ds.fixed = True 8461 8462 # Execute the script. 8463 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8464 8465 # The original parameters. 8466 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8467 pA = 0.7654321 8468 kex = 1234.56789 8469 delta_omega = [7.0, 9.0] 8470 8471 # The R20 keys. 8472 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8473 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8474 8475 # Switch to the 'TP02' model data pipe, then check for each spin. 8476 self.interpreter.pipe.switch('TP02 - relax_disp') 8477 spin_index = 0 8478 for spin, spin_id in spin_loop(return_id=True): 8479 # Printout. 8480 print("\nSpin %s." % spin_id) 8481 8482 # Check the fitted parameters. 8483 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8484 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8485 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8486 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8487 8488 # Increment the spin index. 8489 spin_index += 1
8490 8491
8493 """System test of the value.write function to write intensities for an R1rho setup. 8494 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8495 8496 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8497 """ 8498 8499 # Load the state. 8500 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8501 self.interpreter.state.load(statefile, force=True) 8502 8503 # Set filepaths. 8504 int_filepath = ds.tmpdir+sep+'int.out' 8505 8506 # Write out the intensity parameter file. 8507 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8508 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8509 8510 # Test the file exists. 8511 self.assert_(access(int_filepath, F_OK)) 8512 8513 # Open the files for testing. 8514 int_file = open(int_filepath, 'r') 8515 8516 # Loop over the intensity file to test values. 8517 for line in int_file: 8518 # Skip lines starting with #. 8519 if line[0] == "#": 8520 continue 8521 8522 # Split the line 8523 linesplit = line.split() 8524 8525 # Assume values 8526 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8527 self.assertEqual(linesplit[5], "115571.4") 8528 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8529 self.assertEqual(linesplit[5], "68377.52") 8530 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8531 self.assertEqual(linesplit[5], "9141.689") 8532 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8533 self.assertEqual(linesplit[5], "29123.77") 8534 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8535 self.assertEqual(linesplit[5], "58914.94") 8536 8537 # Close files 8538 int_file.close()
8539 8540
8542 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8543 8544 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8545 """ 8546 8547 # Load the state. 8548 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8549 self.interpreter.state.load(statefile, force=True) 8550 8551 # Set filepaths. 8552 theta_filepath = ds.tmpdir+sep+'theta.out' 8553 8554 # Write out the theta parameter file. 8555 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8556 8557 # Test the file exists. 8558 self.assert_(access(theta_filepath, F_OK)) 8559 8560 # Open the files for testing. 8561 theta_file = open(theta_filepath, 'r') 8562 8563 # Loop over the theta file to test values. 8564 for line in theta_file: 8565 # Skip lines starting with #. 8566 if line[0] == "#": 8567 continue 8568 # Print lines, not including newline character. 8569 print(line[:-1]) 8570 8571 # Split the line 8572 linesplit = line.split() 8573 8574 # Assume values 8575 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8576 self.assertNotEqual(linesplit[5], "None") 8577 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8578 self.assertNotEqual(linesplit[5], "None") 8579 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8580 self.assertNotEqual(linesplit[5], "None") 8581 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8582 self.assertNotEqual(linesplit[5], "None") 8583 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8584 self.assertNotEqual(linesplit[5], "None") 8585 8586 # Close files 8587 theta_file.close()
8588 8589
8591 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8592 8593 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8594 """ 8595 8596 # Load the state. 8597 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8598 self.interpreter.state.load(statefile, force=True) 8599 8600 # Set filepaths. 8601 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8602 8603 # Write out the w_eff parameter file. 8604 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8605 8606 # Test the file exists. 8607 self.assert_(access(w_eff_filepath, F_OK)) 8608 8609 # Open the files for testing. 8610 w_eff_file = open(w_eff_filepath, 'r') 8611 8612 # Loop over the w_eff file to test values. 8613 for line in w_eff_file: 8614 # Skip lines starting with #. 8615 if line[0] == "#": 8616 continue 8617 # Print lines, not including newline character. 8618 print(line[:-1]) 8619 8620 # Split the line 8621 linesplit = line.split() 8622 8623 # Assume values 8624 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8625 self.assertNotEqual(linesplit[5], "None") 8626 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8627 self.assertNotEqual(linesplit[5], "None") 8628 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8629 self.assertNotEqual(linesplit[5], "None") 8630 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8631 self.assertNotEqual(linesplit[5], "None") 8632 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8633 self.assertNotEqual(linesplit[5], "None") 8634 8635 # Close files 8636 w_eff_file.close()
8637 8638
8640 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8641 8642 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8643 """ 8644 8645 # Load the state. 8646 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8647 self.interpreter.state.load(statefile, force=True) 8648 8649 # Set pipe name, bundle and type. 8650 pipe_name = 'base pipe' 8651 pipe_bundle = 'relax_disp' 8652 pipe_type = 'relax_disp' 8653 8654 # The path to the data files. 8655 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8656 8657 # Deselect all spins 8658 self.interpreter.deselect.all() 8659 8660 # Specify spins to be selected. 8661 select_spin_ids = [ 8662 ":13@N", 8663 ":15@N", 8664 ":16@N", 8665 ":25@N", 8666 ":26@N", 8667 ":28@N", 8668 ":39@N", 8669 ":40@N", 8670 ":41@N", 8671 ":43@N", 8672 ":44@N", 8673 ":45@N", 8674 ":49@N", 8675 ":52@N", 8676 ":53@N"] 8677 8678 # Reverse the selection for the spins. 8679 for curspin in select_spin_ids: 8680 print("Selecting spin %s"%curspin) 8681 self.interpreter.deselect.reverse(spin_id=curspin) 8682 8683 # Read the R1 data 8684 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 8685 8686 # The dispersion models. 8687 MODELS = ['R2eff'] 8688 8689 # The grid search size (the number of increments per dimension). 8690 GRID_INC = 4 8691 8692 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8693 MC_NUM = 3 8694 8695 # Model selection technique. 8696 MODSEL = 'AIC' 8697 8698 # Execute the auto-analysis (fast). 8699 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8700 OPT_FUNC_TOL = 1e-1 8701 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8702 OPT_MAX_ITERATIONS = 1000 8703 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8704 8705 # Run the analysis. 8706 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 8707 8708 ## Check for file creation 8709 # Set filepaths. 8710 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8711 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8712 8713 # Test the files exists. 8714 self.assert_(access(theta_filepath, F_OK)) 8715 self.assert_(access(w_eff_filepath, F_OK)) 8716 8717 # Open the files for testing. 8718 theta_file = open(theta_filepath, 'r') 8719 theta_result = [ 8720 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8721 "#\n", 8722 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8723 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8724 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8725 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8726 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8727 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8728 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8729 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8730 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 8731 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8732 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 8733 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 8734 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8735 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8736 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8737 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8738 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8739 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 8740 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 8741 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8742 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 8743 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8744 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8745 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8746 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8747 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8748 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8749 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8750 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8751 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8752 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 8753 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 8754 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 8755 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8756 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 8757 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 8758 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 8759 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8760 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8761 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 8762 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8763 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8764 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 8765 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 8766 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8767 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8768 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8769 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8770 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8771 ] 8772 # Check the created theta file. 8773 lines = theta_file.readlines() 8774 for i in range(len(lines)): 8775 # Test lines starting with # 8776 if theta_result[i][0] == "#": 8777 self.assertEqual(theta_result[i], lines[i]) 8778 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8779 if theta_result[i] == lines[i]: 8780 self.assertEqual(theta_result[i], lines[i]) 8781 # If the line is not equal each other, make a slower comparison of values. 8782 else: 8783 # Print lines if they don't match. To help find differences. 8784 print(theta_result[i]) 8785 print(lines[i]) 8786 8787 # First test first 62 characters containing spin information 8788 self.assertEqual(theta_result[i][:62], lines[i][:62]) 8789 8790 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8791 theta_result_s = theta_result[i][62:].split()[::2] 8792 print(theta_result_s ) 8793 lines_s = lines[i][62:].split()[::2] 8794 print(lines_s) 8795 # Loop over the value elements 8796 for j in range(len(lines_s)): 8797 print(theta_result_s[j], lines_s[j]) 8798 # Assume a precision to digits. 8799 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 8800 8801 # Close file 8802 theta_file.close() 8803 8804 w_eff_file = open(w_eff_filepath, 'r') 8805 w_eff_result = [ 8806 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 8807 "#\n", 8808 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8809 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8810 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8811 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8812 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8813 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8814 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8815 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8816 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 8817 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8818 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 8819 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 8820 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8821 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8822 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8823 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8824 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8825 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 8826 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 8827 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8828 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 8829 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8830 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8831 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8832 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8833 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8834 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8835 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8836 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8837 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8838 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 8839 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 8840 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 8841 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8842 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 8843 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 8844 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 8845 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8846 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8847 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 8848 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8849 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8850 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 8851 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 8852 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8853 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8854 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8855 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8856 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 8857 ] 8858 # Check the created w_eff file. 8859 lines = w_eff_file.readlines() 8860 for i in range(len(lines)): 8861 # Test lines starting with # 8862 if w_eff_result[i][0] == "#": 8863 self.assertEqual(w_eff_result[i], lines[i]) 8864 # If the line is equal each other, make a line comparison. This should catch lines with None values. 8865 if w_eff_result[i] == lines[i]: 8866 self.assertEqual(w_eff_result[i], lines[i]) 8867 # If the line is not equal each other, make a slower comparison of values. 8868 else: 8869 # Print lines if they don't match. To help find differences. 8870 print(w_eff_result[i]) 8871 print(lines[i]) 8872 8873 # First test first 62 characters containing spin information 8874 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 8875 8876 # Make a string split after 62 characters. Select each second element, so None values are skipped. 8877 w_eff_result_s = w_eff_result[i][62:].split()[::2] 8878 print(w_eff_result_s ) 8879 lines_s = lines[i][62:].split()[::2] 8880 print(lines_s) 8881 # Loop over the value elements 8882 for j in range(len(lines_s)): 8883 print(w_eff_result_s[j], lines_s[j]) 8884 # Assume a precision to digits. 8885 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 8886 8887 # Close file 8888 w_eff_file.close()
8889 8890
8892 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 8893 8894 This follows Task 7822. 8895 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 8896 8897 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 8898 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 8899 """ 8900 8901 # Load the data. 8902 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 8903 8904 # Set pipe name, bundle and type. 8905 pipe_name = 'base pipe' 8906 pipe_bundle = 'relax_disp' 8907 pipe_type = 'relax_disp' 8908 8909 # Create the data pipe. 8910 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 8911 8912 file = data_path + '1_setup_r1rho_GUI.py' 8913 self.interpreter.script(file=file, dir=None) 8914 8915 # Deselect all spins. 8916 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 8917 8918 # Select one spin. 8919 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 8920 8921 # Set the model. 8922 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8923 8924 # Check if intensity errors have already been calculated. 8925 check_intensity_errors() 8926 8927 # Do a grid search. 8928 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 8929 8930 # Set algorithm. 8931 min_algor = 'Newton' 8932 constraints = True 8933 if constraints: 8934 min_options = ('%s'%(min_algor),) 8935 #min_algor = 'Log barrier' 8936 min_algor = 'Method of Multipliers' 8937 scaling_matrix = assemble_scaling_matrix(scaling=True) 8938 8939 # Collect spins 8940 all_spin_ids = [] 8941 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8942 all_spin_ids.append(spin_id) 8943 8944 spins = spin_ids_to_containers(all_spin_ids[:1]) 8945 8946 # Get constraints 8947 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 8948 else: 8949 min_options = () 8950 A, b = None, None 8951 min_options = () 8952 sim_boot = 200 8953 scaling_list = [1.0, 1.0] 8954 8955 # Minimise. 8956 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 8957 8958 # Loop over old err attributes. 8959 err_attr_list = ['r2eff_err', 'i0_err'] 8960 8961 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8962 # Loop over old err attributes. 8963 for err_attr in err_attr_list: 8964 if hasattr(cur_spin, err_attr): 8965 delattr(cur_spin, err_attr) 8966 8967 # Collect the estimation data from boot. 8968 my_dic = {} 8969 param_key_list = [] 8970 est_keys = [] 8971 est_key = '-2' 8972 est_keys.append(est_key) 8973 spin_id_list = [] 8974 8975 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8976 # Add key to dic. 8977 my_dic[spin_id] = {} 8978 8979 # Add key for estimate. 8980 my_dic[spin_id][est_key] = {} 8981 8982 # Add spin key to list. 8983 spin_id_list.append(spin_id) 8984 8985 # Generate spin string. 8986 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8987 8988 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8989 # Generate the param_key. 8990 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8991 8992 # Append key. 8993 param_key_list.append(param_key) 8994 8995 # Add key to dic. 8996 my_dic[spin_id][est_key][param_key] = {} 8997 8998 values = [] 8999 errors = [] 9000 times = [] 9001 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9002 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9003 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9004 times.append(time) 9005 9006 # Convert to numpy array. 9007 values = asarray(values) 9008 errors = asarray(errors) 9009 times = asarray(times) 9010 9011 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9012 i0 = getattr(cur_spin, 'i0')[param_key] 9013 9014 R_m_sim_l = [] 9015 I0_m_sim_l = [] 9016 for j in range(sim_boot): 9017 if j in range(0, 100000, 100): 9018 print("Simulation %i"%j) 9019 # Start minimisation. 9020 9021 # Produce errors 9022 I_err = [] 9023 for j, error in enumerate(errors): 9024 I_error = gauss(values[j], error) 9025 I_err.append(I_error) 9026 # Convert to numpy array. 9027 I_err = asarray(I_err) 9028 9029 x0 = [r2eff, i0] 9030 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9031 9032 # Ref input. 9033 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9034 # l=l, u=u, c=c, dc=dc, d2c=d2c 9035 # l: Lower bound constraint vector (l <= x <= u). 9036 # u: Upper bound constraint vector (l <= x <= u). 9037 # c: User supplied constraint function. 9038 # dc: User supplied constraint gradient function. 9039 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9040 9041 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9042 R_m_sim_l.append(R_m_sim_j) 9043 I0_m_sim_l.append(I0_m_sim_j) 9044 9045 # Get stats on distribution. 9046 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9047 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9048 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9049 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9050 9051 # Estimate R2eff errors. 9052 self.interpreter.relax_disp.r2eff_err_estimate() 9053 9054 est_key = '-1' 9055 est_keys.append(est_key) 9056 9057 # Collect data. 9058 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9059 # Add key for estimate. 9060 my_dic[spin_id][est_key] = {} 9061 9062 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9063 # Generate the param_key. 9064 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9065 9066 # Add key to dic. 9067 my_dic[spin_id][est_key][param_key] = {} 9068 9069 # Get the value. 9070 # Loop over err attributes. 9071 for err_attr in err_attr_list: 9072 if hasattr(cur_spin, err_attr): 9073 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9074 else: 9075 get_err_attr = 0.0 9076 9077 # Save to dic. 9078 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9079 9080 9081 # Make Carlo Simulations number 9082 mc_number_list = list(range(0, 1000, 250)) 9083 9084 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9085 9086 # Loop over the Monte Carlo simulations: 9087 for number in mc_number_list: 9088 # First delete old simulations. 9089 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9090 # Loop over old err attributes. 9091 for err_attr in err_attr_list: 9092 if hasattr(cur_spin, err_attr): 9093 delattr(cur_spin, err_attr) 9094 9095 # Loop over the simulated attributes. 9096 for sim_attr in sim_attr_list: 9097 if hasattr(cur_spin, sim_attr): 9098 delattr(cur_spin, sim_attr) 9099 9100 self.interpreter.monte_carlo.setup(number=number) 9101 self.interpreter.monte_carlo.create_data() 9102 self.interpreter.monte_carlo.initial_values() 9103 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9104 self.interpreter.eliminate() 9105 self.interpreter.monte_carlo.error_analysis() 9106 9107 est_key = '%i'%number 9108 est_keys.append(est_key) 9109 9110 # Collect data. 9111 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9112 # Add key for estimate. 9113 my_dic[spin_id][est_key] = {} 9114 9115 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9116 # Generate the param_key. 9117 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9118 9119 # Add key to dic. 9120 my_dic[spin_id][est_key][param_key] = {} 9121 9122 # Get the value. 9123 # Loop over err attributes. 9124 for err_attr in err_attr_list: 9125 if hasattr(cur_spin, err_attr): 9126 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9127 else: 9128 get_err_attr = 0.0 9129 9130 # Save to dic. 9131 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9132 9133 # Set what to extract. 9134 err_attr = err_attr_list[0] 9135 9136 # Define list with text. 9137 text_list = [] 9138 9139 # Now loop through the data. 9140 for spin_id in spin_id_list: 9141 for est_key in est_keys: 9142 # Define list to pickup data. 9143 r2eff_err_list = [] 9144 9145 for param_key in param_key_list: 9146 # Get the value. 9147 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9148 9149 # Add to list. 9150 r2eff_err_list.append(r2eff_err) 9151 9152 # Sum the list 9153 sum_array = sum(array(r2eff_err_list)) 9154 9155 # Join floats to string. 9156 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9157 9158 # Define print string. 9159 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9160 text_list.append(text) 9161 9162 9163 # Now print. 9164 filepath = NamedTemporaryFile(delete=False).name 9165 # Open the files for testing. 9166 w_file = open(filepath, 'w') 9167 9168 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9169 9170 for text in text_list: 9171 # Print. 9172 print(text) 9173 9174 # Write to file. 9175 w_file.write(text+"\n") 9176 9177 # Close files 9178 w_file.close() 9179 9180 print("Filepath is: %s"%filepath) 9181 print("Start 'gnuplot' and write:") 9182 print("set term dumb") 9183 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9184 9185
9186 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9187 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9188 9189 # Check the kex value of residue 52 9190 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9191 9192 # Print results for each model. 9193 print("\n\n################") 9194 print("Printing results") 9195 print("################\n") 9196 for model in models: 9197 # Skip R2eff model. 9198 if model == MODEL_R2EFF: 9199 continue 9200 9201 # Switch to pipe. 9202 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9203 print("\nModel: %s" % (model)) 9204 9205 # Loop over the spins. 9206 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9207 # Generate spin string. 9208 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9209 9210 # Loop over the parameters. 9211 print("Optimised parameters for spin: %s" % (spin_string)) 9212 for param in cur_spin.params + ['chi2']: 9213 # Get the value. 9214 if param in ['r1', 'r2']: 9215 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9216 # Generate the R20 key. 9217 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9218 9219 # Get the value. 9220 value = getattr(cur_spin, param)[r20_key] 9221 9222 # Print value. 9223 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9224 9225 # Compare values. 9226 if spin_id == ':52@N': 9227 if param == 'r1': 9228 if model == MODEL_NOREX: 9229 if r2eff_estimate == 'direct': 9230 self.assertAlmostEqual(value, 1.46138805) 9231 elif r2eff_estimate == 'MC2000': 9232 self.assertAlmostEqual(value, 1.46328102) 9233 elif r2eff_estimate == 'chi2_pyt': 9234 self.assertAlmostEqual(value, 1.43820629) 9235 elif model == MODEL_DPL94: 9236 if r2eff_estimate == 'direct': 9237 self.assertAlmostEqual(value, 1.44845742) 9238 elif r2eff_estimate == 'MC2000': 9239 self.assertAlmostEqual(value, 1.45019848) 9240 elif r2eff_estimate == 'chi2_pyt': 9241 self.assertAlmostEqual(value, 1.44666512) 9242 elif model == MODEL_TP02: 9243 if r2eff_estimate == 'direct': 9244 self.assertAlmostEqual(value, 1.54354392) 9245 elif r2eff_estimate == 'MC2000': 9246 self.assertAlmostEqual(value, 1.54352369) 9247 elif r2eff_estimate == 'chi2_pyt': 9248 self.assertAlmostEqual(value, 1.55964020) 9249 elif model == MODEL_TAP03: 9250 if r2eff_estimate == 'direct': 9251 self.assertAlmostEqual(value, 1.54356410) 9252 elif r2eff_estimate == 'MC2000': 9253 self.assertAlmostEqual(value, 1.54354367) 9254 elif r2eff_estimate == 'chi2_pyt': 9255 self.assertAlmostEqual(value, 1.55967157) 9256 elif model == MODEL_MP05: 9257 if r2eff_estimate == 'direct': 9258 self.assertAlmostEqual(value, 1.54356416) 9259 elif r2eff_estimate == 'MC2000': 9260 self.assertAlmostEqual(value, 1.54354372) 9261 elif r2eff_estimate == 'chi2_pyt': 9262 self.assertAlmostEqual(value, 1.55967163) 9263 elif model == MODEL_NS_R1RHO_2SITE: 9264 if r2eff_estimate == 'direct': 9265 self.assertAlmostEqual(value, 1.41359221, 5) 9266 elif r2eff_estimate == 'MC2000': 9267 self.assertAlmostEqual(value, 1.41321968, 5) 9268 elif r2eff_estimate == 'chi2_pyt': 9269 self.assertAlmostEqual(value, 1.36303129, 5) 9270 9271 elif param == 'r2': 9272 if model == MODEL_NOREX: 9273 if r2eff_estimate == 'direct': 9274 self.assertAlmostEqual(value, 11.48392439) 9275 elif r2eff_estimate == 'MC2000': 9276 self.assertAlmostEqual(value, 11.48040934) 9277 elif r2eff_estimate == 'chi2_pyt': 9278 self.assertAlmostEqual(value, 11.47224488) 9279 elif model == MODEL_DPL94: 9280 if r2eff_estimate == 'direct': 9281 self.assertAlmostEqual(value, 10.15688372, 6) 9282 elif r2eff_estimate == 'MC2000': 9283 self.assertAlmostEqual(value, 10.16304887, 6) 9284 elif r2eff_estimate == 'chi2_pyt': 9285 self.assertAlmostEqual(value, 9.20037797, 6) 9286 elif model == MODEL_TP02: 9287 if r2eff_estimate == 'direct': 9288 self.assertAlmostEqual(value, 9.72654896, 6) 9289 elif r2eff_estimate == 'MC2000': 9290 self.assertAlmostEqual(value, 9.72772726, 6) 9291 elif r2eff_estimate == 'chi2_pyt': 9292 self.assertAlmostEqual(value, 9.53948340, 6) 9293 elif model == MODEL_TAP03: 9294 if r2eff_estimate == 'direct': 9295 self.assertAlmostEqual(value, 9.72641887, 6) 9296 elif r2eff_estimate == 'MC2000': 9297 self.assertAlmostEqual(value, 9.72759374, 6) 9298 elif r2eff_estimate == 'chi2_pyt': 9299 self.assertAlmostEqual(value, 9.53926913, 6) 9300 elif model == MODEL_MP05: 9301 if r2eff_estimate == 'direct': 9302 self.assertAlmostEqual(value, 9.72641723, 6) 9303 elif r2eff_estimate == 'MC2000': 9304 self.assertAlmostEqual(value, 9.72759220, 6) 9305 elif r2eff_estimate == 'chi2_pyt': 9306 self.assertAlmostEqual(value, 9.53926778, 6) 9307 elif model == MODEL_NS_R1RHO_2SITE: 9308 if r2eff_estimate == 'direct': 9309 self.assertAlmostEqual(value, 9.34531535, 5) 9310 elif r2eff_estimate == 'MC2000': 9311 self.assertAlmostEqual(value, 9.34602793, 5) 9312 elif r2eff_estimate == 'chi2_pyt': 9313 self.assertAlmostEqual(value, 9.17631409, 5) 9314 9315 # For all other parameters. 9316 else: 9317 # Get the value. 9318 value = getattr(cur_spin, param) 9319 9320 # Print value. 9321 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9322 9323 # Compare values. 9324 if spin_id == ':52@N': 9325 if param == 'phi_ex': 9326 if model == MODEL_DPL94: 9327 if r2eff_estimate == 'direct': 9328 self.assertAlmostEqual(value, 0.07599563) 9329 elif r2eff_estimate == 'MC2000': 9330 self.assertAlmostEqual(value, 0.07561937) 9331 elif r2eff_estimate == 'chi2_pyt': 9332 self.assertAlmostEqual(value, 0.12946061) 9333 9334 elif param == 'pA': 9335 if model == MODEL_TP02: 9336 if r2eff_estimate == 'direct': 9337 self.assertAlmostEqual(value, 0.88827040) 9338 elif r2eff_estimate == 'MC2000': 9339 self.assertAlmostEqual(value, 0.88807487) 9340 elif r2eff_estimate == 'chi2_pyt': 9341 self.assertAlmostEqual(value, 0.87746233) 9342 elif model == MODEL_TAP03: 9343 if r2eff_estimate == 'direct': 9344 self.assertAlmostEqual(value, 0.88828922) 9345 elif r2eff_estimate == 'MC2000': 9346 self.assertAlmostEqual(value, 0.88809318) 9347 elif r2eff_estimate == 'chi2_pyt': 9348 self.assertAlmostEqual(value, 0.87747558) 9349 elif model == MODEL_MP05: 9350 if r2eff_estimate == 'direct': 9351 self.assertAlmostEqual(value, 0.88828924, 6) 9352 elif r2eff_estimate == 'MC2000': 9353 self.assertAlmostEqual(value, 0.88809321) 9354 elif r2eff_estimate == 'chi2_pyt': 9355 self.assertAlmostEqual(value, 0.87747562) 9356 elif model == MODEL_NS_R1RHO_2SITE: 9357 if r2eff_estimate == 'direct': 9358 self.assertAlmostEqual(value, 0.94504369, 6) 9359 elif r2eff_estimate == 'MC2000': 9360 self.assertAlmostEqual(value, 0.94496541, 6) 9361 elif r2eff_estimate == 'chi2_pyt': 9362 self.assertAlmostEqual(value, 0.92084707, 6) 9363 9364 elif param == 'dw': 9365 if model == MODEL_TP02: 9366 if r2eff_estimate == 'direct': 9367 self.assertAlmostEqual(value, 1.08875840, 6) 9368 elif r2eff_estimate == 'MC2000': 9369 self.assertAlmostEqual(value, 1.08765638, 6) 9370 elif r2eff_estimate == 'chi2_pyt': 9371 self.assertAlmostEqual(value, 1.09753230, 6) 9372 elif model == MODEL_TAP03: 9373 if r2eff_estimate == 'direct': 9374 self.assertAlmostEqual(value, 1.08837238, 6) 9375 elif r2eff_estimate == 'MC2000': 9376 self.assertAlmostEqual(value, 1.08726698, 6) 9377 elif r2eff_estimate == 'chi2_pyt': 9378 self.assertAlmostEqual(value, 1.09708821, 6) 9379 elif model == MODEL_MP05: 9380 if r2eff_estimate == 'direct': 9381 self.assertAlmostEqual(value, 1.08837241, 6) 9382 elif r2eff_estimate == 'MC2000': 9383 self.assertAlmostEqual(value, 1.08726706, 6) 9384 elif r2eff_estimate == 'chi2_pyt': 9385 self.assertAlmostEqual(value, 1.09708832, 6) 9386 elif model == MODEL_NS_R1RHO_2SITE: 9387 if r2eff_estimate == 'direct': 9388 self.assertAlmostEqual(value, 1.56001812, 5) 9389 elif r2eff_estimate == 'MC2000': 9390 self.assertAlmostEqual(value, 1.55833321, 5) 9391 elif r2eff_estimate == 'chi2_pyt': 9392 self.assertAlmostEqual(value, 1.36406712, 5) 9393 9394 elif param == 'kex': 9395 if model == MODEL_DPL94: 9396 if r2eff_estimate == 'direct': 9397 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9398 elif r2eff_estimate == 'MC2000': 9399 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9400 elif r2eff_estimate == 'chi2_pyt': 9401 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9402 elif model == MODEL_TP02: 9403 if r2eff_estimate == 'direct': 9404 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9405 elif r2eff_estimate == 'MC2000': 9406 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9407 elif r2eff_estimate == 'chi2_pyt': 9408 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9409 elif model == MODEL_TAP03: 9410 if r2eff_estimate == 'direct': 9411 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9412 elif r2eff_estimate == 'MC2000': 9413 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9414 elif r2eff_estimate == 'chi2_pyt': 9415 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9416 elif model == MODEL_MP05: 9417 if r2eff_estimate == 'direct': 9418 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9419 elif r2eff_estimate == 'MC2000': 9420 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9421 elif r2eff_estimate == 'chi2_pyt': 9422 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9423 elif model == MODEL_NS_R1RHO_2SITE: 9424 if r2eff_estimate == 'direct': 9425 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9426 elif r2eff_estimate == 'MC2000': 9427 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9428 elif r2eff_estimate == 'chi2_pyt': 9429 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9430 9431 elif param == 'chi2': 9432 if model == MODEL_NOREX: 9433 if r2eff_estimate == 'direct': 9434 self.assertAlmostEqual(value, 848.42016907, 5) 9435 elif r2eff_estimate == 'MC2000': 9436 self.assertAlmostEqual(value, 3363.95829122, 5) 9437 elif r2eff_estimate == 'chi2_pyt': 9438 self.assertAlmostEqual(value, 5976.49946726, 5) 9439 elif model == MODEL_DPL94: 9440 if r2eff_estimate == 'direct': 9441 self.assertAlmostEqual(value, 179.47041241) 9442 elif r2eff_estimate == 'MC2000': 9443 self.assertAlmostEqual(value, 710.24767560) 9444 elif r2eff_estimate == 'chi2_pyt': 9445 self.assertAlmostEqual(value, 612.72616697, 5) 9446 elif model == MODEL_TP02: 9447 if r2eff_estimate == 'direct': 9448 self.assertAlmostEqual(value, 29.33882530, 6) 9449 elif r2eff_estimate == 'MC2000': 9450 self.assertAlmostEqual(value, 114.47142772, 6) 9451 elif r2eff_estimate == 'chi2_pyt': 9452 self.assertAlmostEqual(value, 250.50838162, 5) 9453 elif model == MODEL_TAP03: 9454 if r2eff_estimate == 'direct': 9455 self.assertAlmostEqual(value, 29.29050673, 6) 9456 elif r2eff_estimate == 'MC2000': 9457 self.assertAlmostEqual(value, 114.27987534) 9458 elif r2eff_estimate == 'chi2_pyt': 9459 self.assertAlmostEqual(value, 250.04050719, 5) 9460 elif model == MODEL_MP05: 9461 if r2eff_estimate == 'direct': 9462 self.assertAlmostEqual(value, 29.29054301, 6) 9463 elif r2eff_estimate == 'MC2000': 9464 self.assertAlmostEqual(value, 114.28002272) 9465 elif r2eff_estimate == 'chi2_pyt': 9466 self.assertAlmostEqual(value, 250.04077478, 5) 9467 elif model == MODEL_NS_R1RHO_2SITE: 9468 if r2eff_estimate == 'direct': 9469 self.assertAlmostEqual(value, 34.44010543, 6) 9470 elif r2eff_estimate == 'MC2000': 9471 self.assertAlmostEqual(value, 134.14368365) 9472 elif r2eff_estimate == 'chi2_pyt': 9473 self.assertAlmostEqual(value, 278.55121388, 5) 9474 9475 9476 # Print the final pipe. 9477 model = 'final' 9478 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9479 print("\nFinal pipe") 9480 9481 # Loop over the spins. 9482 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9483 # Generate spin string. 9484 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9485 9486 # Loop over the parameters. 9487 print("Optimised model for spin: %s" % (spin_string)) 9488 param = 'model' 9489 9490 # Get the value. 9491 value = getattr(cur_spin, param) 9492 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9493 9494 9495 ### Now check some of the written out files. 9496 file_names = ['r1rho_prime', 'r1'] 9497 9498 for file_name_i in file_names: 9499 9500 # Make the file name. 9501 file_name = "%s.out" % file_name_i 9502 9503 # Get the file path. 9504 file_path = get_file_path(file_name, result_dir_name + sep + model) 9505 9506 # Test the file exists. 9507 print("Testing file access to: %s"%file_path) 9508 self.assert_(access(file_path, F_OK)) 9509 9510 # Now open, and compare content, line by line. 9511 file_prod = open(file_path) 9512 lines_prod = file_prod.readlines() 9513 file_prod.close() 9514 9515 # Loop over the lines. 9516 for i, line in enumerate(lines_prod): 9517 # Make the string test 9518 line_split = line.split() 9519 9520 # Continue for comment lines. 9521 if line_split[0] == "#": 9522 print(line), 9523 continue 9524 9525 # Assign the split of the line. 9526 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9527 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9528 9529 if res_num == '52': 9530 # Assert that the value is not None. 9531 self.assertNotEqual(val, 'None')
9532